Когда я добираюсь до третьего цикла, он взрывается, потому что он не может найти «Строка» на столе. Зачем?Разбор динамического JSON с Newtonsoft.JSON отсутствует массив в десериализованном объекте
var converter = new ExpandoObjectConverter();
dynamic deserializeObject = JsonConvert.DeserializeObject<ExpandoObject>(jsonString, converter);
foreach (var model in deserializeObject.Model)
{
foreach (var table in model.Table)
{
foreach (var row in table.Row)
{
Console.WriteLine(row.BookId + ": " + row.BookName);
}
}
}
JSON:
{
"Model": [
{
"Field1": "Field1Value",
"Field2": "Field2Value",
"Field3": "Field3Value",
"Table": {
"Row": [
{
"BookId": "1",
"BookName": "Computer Architecture",
"Category": "Computers",
"Price": "125.60"
},
{
"BookId": "2",
"BookName": "Asp.Net 4 Blue Book",
"Category": "Programming",
"Price": "56.00"
},
{
"BookId": "3",
"BookName": "Popular Science",
"Category": "Science",
"Price": "210.40"
},
{
"BookId": "4",
"BookName": "Mission Impossible",
"Category": "Adventure",
"Price": "210.40"
}
]
}
},
{
"ClientFirstName": "Jane",
"ClientLastName": "Doe",
"Table": [
{
"Row": [
{
"BookId": "1",
"BookName": "Computer Architecture",
"Category": "Computers",
"Price": "125.60"
},
{
"BookId": "3",
"BookName": "Popular Science",
"Category": "Science",
"Price": "210.40"
},
{
"BookId": "4",
"BookName": "Mission Impossible",
"Category": "Adventure",
"Price": "210.40"
}
]
},
{
"Row": [
{
"BookId": "1",
"BookName": "Computer Architecture",
"Category": "Computers",
"Price": "125.60"
},
{
"BookId": "4",
"BookName": "Mission Impossible",
"Category": "Adventure",
"Price": "210.40"
}
]
}
]
}
]
}
проверить в JSON http://jsonlint.com/ – tofutim
Код переформатирован – Thomas