我的RootObject
[JsonProperty("status")]
public string Status {
get;
set;
}
[JsonProperty("error")]
public ErrosHelper Error {
get;
set;
}
[JsonProperty("resource")]
public List<List<int>> Resource {
get;
set;
}
Json回应。
{ “状态”: “成功”, “资源”:{ “1”:{ “1”: “30”, “2”: “23”, “3”: “43”}, “2” :{ “1”: “34”, “2”: “54”, “3”: “32”}, “3”:{ “1”: “56”, “2”: “43”,“3 “:” 39 “},” 4 “:{” 1 “:” 23" , “2”: “32”, “3”: “31”}, “5”:{ “1”: “34”, “2”: “37”, “3”: “29”}, “6”:{ “1”: “38”, “2”: “34”, “3”: “45”}, “7” :{ “1”: “67”, “2”: “53”, “3”: “67”}, “8”:{ “1”: “45”, “2”: “23”,“3 “:” 78 “},” 9 “:{” 1 “:” 54" , “2”: “44”, “3”: “56”}, “10”:{ “1”: “46”, “2”: “23”, “3”: “45”}, “11”:{ “1”: “77”, “2”: “56”, “3”: “78”}, “12” :{ “1”: “34”, “2”: “21”, “3”: “65”}, “13”:{ “1”: “46”, “2”: “23”,“3 “:” 45 “},” 14 “:{” 1 “:” 77" , “2”: “56”, “3”: “78”}, “15”:{ “1”: “34”, “2”: “21”, “3”: “65”}, “16”:{ “1”: “46”, “2”: “23”, “3”: “45”}, “17” :{ “1”: “77”, “2”: “56”, “3”: “78”}, “18”:{ “1”: “34”, “2”: “21”,“3 “:” 65 “},” 19 “:{” 1 “:” 46" , “2”: “23”, “3”: “45”}, “20”:{ “1”: “77”, “2”: “56”, “3”: “78”}}}
我有回应,给我Json字符串。如何将此字符串反序列化为我的对象?
答案 0 :(得分:4)
你的对象是错的。 您显示的JSON没有int列表,而是字典词典。
如果您将其更改为
public class Root {
[JsonProperty("status")]
public string Status {
get;
set;
}
[JsonProperty("resource")]
public Dictionary<string, Dictionary<string, int>> Resource {
get;
set;
}
}
它将使用JsonConvert.DeserializeObject<Root>(json);