gpt4 book ai didi

c# - 反序列化 json 数组以列出 wp7

转载 作者:行者123 更新时间:2023-11-30 18:00:12 25 4
gpt4 key购买 nike

我需要从 json 中的子数组中获取数据,但它没有被转换成列表,下面是我的 json 字符串

{“responseCode”:“0”,“responseObject”:{“TotalRecords”:25,“TotalDisplayRecords”:25,“aaData”:[{“InvoiceId”:16573,“somedata..},”appCrmAccount(一些标题,总共100个这样的标题)amount":40086.00,"invoiceNumber":"12,accountName":"dfgAsfsadf","dueDateStr":"04/24/2012"(待入列表的数据)

这是我的代码:

var djson = new DataContractJsonSerializer(typeof(dataList));
var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
dataList result = (dataList)djson.ReadObject(stream);//not getting execute

请帮助..提前致谢。

最佳答案

试试这个

private void btnAdd_Click(object sender, RoutedEventArgs e)
{
WebClient proxy = new WebClient();
proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted);
proxy.DownloadStringAsync(new Uri(""));
}

并且需要解析返回的JSON如下。在创建 DataContractJsonSrrializer 实例的参数中,我们传递了学生列表。

void proxy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Stream stream = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));

DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(List<Student>));
List<Student> result = obj.ReadObject(stream) as List<Student>;
lstStudents.ItemsSource = result;
}

关于c# - 反序列化 json 数组以列出 wp7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10309643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com