我需要从 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
请帮助..
提前致谢。
Try this
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
WebClient proxy = new WebClient();
proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted);
proxy.DownloadStringAsync(new Uri(""));
}
并需要解析返回的 JSON,如下所示。在创建 DataContractJsonSrializer 实例的参数中,我们传递学生列表。
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)