【发布时间】:2016-01-22 12:44:17
【问题描述】:
如何解析这个 JSON
使用牛顿软
我试过但给了我 null 因为我的模态应该有 1、2、3 类... 但这是动态的。所以会让人感到困惑。
感谢您的帮助!
{
"data": {
"1": {
"test": {
"col1": "123",
"col2": "name"
}
},
"2": {
"test": {
"col1": "345",
"col2": "name2"
}
},
"3": {
"test": {
"col1": "456",
"col2": "name3"
}
}
}
class root
{
data data{get; set;};
}
class data
{
List<object> innerObject {get; set;} //not sure as labels are dynamic
}
class test
{
col1{get; set;}
col2{get; set;}
} //Calling it in that way ..
root r = JsonConvert.DeserializeObject<root>(result);
【问题讨论】:
-
请出示您的代码
-
class root { data data{get; set;}; } class data { List<object> innerObject {get; set;} //not sure as labels are dynamic } class test { col1{get; set;} col2{get; set;} } //Calling it in that way .. root r = JsonConvert.DeserializeObject<root>(result);in r 我将得到所有 json 的对象我不知道我应该在数据类中写什么所以解析内部节点。 -
"data" 不是 json 数组。它是一个对象。所以你不能把它解析为一个数组/列表。
-
@MayankJhawar,您能否请edit您的问题包含代码?
标签: c# asp.net json nested json.net