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

标签 c# .net json windows-phone-7

我需要从 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/

相关文章:

c# - 如何通过Word文档修改 "walk"的内容?

jquery - JSON 对象映射到另一个 JSON 对象到备用键名称

c# - 将 DateTime 转换为字符串 "yyyy-mm-dd"

c# - 为什么尽管签名中有返回类型,但此方法仍保持动态返回?

python - 在python中将一个json字典添加到另一个json字典中

c# - 读取嵌套的动态 JSON 属性

除英语之外的 C# WritePrivateProfileString() 值

c# - 与字典替代的协方差?

c# - Linq2Sql、OOP、DependencyInjection问题

c# - WPF MVVM 为什么使用 ContentControl + DataTemplate View 而不是直接的 XAML 窗口 View ?