我在一个文本文件中有以下JSON,我试图解析。
{
"0":[68],
"1":[154,78,61],
"2":[89,132,146],
"3":[],
"4":[77,132,146],
"5":[32,132,50],
"6":[],
"7":[114,118,54,44,72,136,156,134,129,82,43,34,51,93,142,67,47,153,160,73,39,149,107,94,145,29,115,53,83,1,35,56,123,66,90,121,155],
"8":[89,146],
"9":[89,146],
"10":[100,135],
"11":[],
"12":[],
"13",[111,131],
"14":[77,124],
"15":[89,146],
"16":[163,126,122],
"17":[100,126,135],
"18":[32,50],
"19":[163,126,122]
}
我的代码是
var map = new List<Dictionary<int, List<int>>>();
using (var r = new StreamReader(@"C:\Development\phase2\dependencymap.json"))
{
var json = r.ReadToEnd();
map = JsonConvert.DeserializeObject<List<Dictionary<int, List<int>>>>(json);
}
但它似乎不喜欢这种格式。我做错了什么?
答案 0 :(得分:3)
JSON格式不正确。检查以下行
"13" , [111,131],
并将其更改为:
"13" : [111,131],
答案 1 :(得分:1)
尝试map = JsonConvert.DeserializeObject<List<Dictionary<String, List<int>>>>(json);
你的键是String,而不是int。