在C#中解析复杂的Json数组 [英] Parsing complicated Json Array in C#

查看:451
本文介绍了在C#中解析复杂的Json数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个json数组:

I have a json array:

{
 "array":[
      {
       "Name_0":"Value_0",
       "Name_1":"Value_1"
      },
      {
       "Name_2":"Value_2",
       "Name_3":"Value_3",
       "Name_4":"Value_4",
       "Name_5":"Value_5"
      }
 ]
}

json数组内部的数据结构不一致. 如何在C#中解析它们? 谢谢!

The data structures inside the json array are not consistent. How can I parse them in C#? Thanks!

推荐答案

一种方法是

var serializer = new JavaScriptSerializer();
var data = serializer
    .Deserialize<Dictionary<string, List<Dictionary<string, string>>>>(input);

这是因为您的json数据结构是这样的.对于最里面的元素,我们有一个Dictionary<string, string>,它嵌套在一个通用列表中,而通用列表又嵌套在另一个通用字典中.

This is because your json data structure is like this. For innermost element we have a Dictionary<string, string> which is nested in a generic list which in turn is nested in another generic dictionary.

这篇关于在C#中解析复杂的Json数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆