使用 JSON 数组创建 RDLC 报告

我正在尝试为我的项目创建RDLC带有数组的报告JSON。该JSON数组来自 API。我已经RDLC使用数据库作为Dataset直接访问的方式制作了报告SQL database,但是如何处理来自JSON数组的API。


我试图JSON在非类型化数据表上获取数组,然后将其合并到类型化数据表。那么应该显示在 上dataset.xsd,但事实并非如此。


public partial class WebForm2 : System.Web.UI.Page

{

    [WebMethod]

    [System.Web.Script.Services.ScriptMethod()]

    protected void Page_Load(object sender, EventArgs e)

    {

        test();

    }


    public void test()

    {

        WebClient client = new WebClient();

        string strJSON = client.DownloadString("Json.txt");

        string chk = strJSON.Replace("\\", "");

        chk = chk.Substring(1, chk.Length - 2);

        DataTable dtUsingMethod = GetJSONToDataTableUsingNewtonSoftDll(chk);

        DataSet1.test_tableDataTable tbl = new DataSet1.test_tableDataTable();

        tbl.Merge(dtUsingMethod);

    }


    public static DataTable GetJSONToDataTableUsingNewtonSoftDll(string JSONData)

    {

        DataTable dt = (DataTable)JsonConvert.DeserializeObject(JSONData, (typeof(DataTable)));

        return dt;

    }

}


预期结果是我想使用 JSON 数组生成报告。


绝地无双
浏览 184回答 1
1回答

临摹微笑

好吧,我找到了一个对我有用的答案。我将其发布在这里希望对其他人也有帮助。这里的问题是我们需要 RDLC 报告的数据源。由于我们无法使用 Sql 数据库,因此我们必须创建自己的自定义数据源。步骤1.添加类文件。步骤 2. 类文件中的代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using Newtonsoft.Json;using Newtonsoft.Json.Linq;using Newtonsoft.Json.Converters;using System.Text;using System.Runtime.Serialization.Formatters;using System.IO;using System.Data;using System.Xml.Serialization;using System.Runtime.Serialization;using Newtonsoft.Json.Serialization;using System.Web.Services;using System.Net;namespace Batch_report{&nbsp; &nbsp; public class batch_data&nbsp;&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; public string plant_sl_no { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string batch_no { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string batch_no_sl { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string batch_index { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string batch_date { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string recp_id { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string recp_name { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string pdt_qty { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string truck_id { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string cust_id { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string load_sent_qty { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public string site { get; set; }&nbsp; &nbsp; }&nbsp; &nbsp; public class Custom_batch&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; [WebMethod]&nbsp; &nbsp; &nbsp; &nbsp; [System.Web.Script.Services.ScriptMethod()]&nbsp; &nbsp; &nbsp; &nbsp; public static List<batch_data> GetEmployeeName()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //List<string> abc = new List<string>();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //string[] arr;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebClient client = new WebClient();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string info = client.DownloadString("http://json.txt");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string chk = info.Replace("\\", "");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chk = chk.Substring(1, chk.Length - 2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<batch_data> obj = new List<batch_data>();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj = JsonConvert.DeserializeObject<List<batch_data>>(chk);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return obj;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}步骤3.构建你的类文件,你将得到一个batch_report.dll文件。将此 .dll 添加到项目的引用文件夹中。步骤 4. 从工具箱添加报告或报告向导。添加时,将打开一个窗口,询问数据集。命名您的数据集,然后在数据源中从下拉列表中选择batch_report。在“可用数据集”中,选择您从中获取数据的方法,在我的例子中是来自 Custom_batch 类,方法是 - GetEmployeeName()。步骤5.单击下一步直到完成,之后您也可以设计您的报告。
打开App,查看更多内容
随时随地看视频慕课网APP