dizisinde eksiktir. Üçüncü döngüye geldiğimde, tablodaki "Satır" ı bulamadığı için havaya uçar. Niye ya?Newtonsoft.JSON ile dinamik JSON ayrıştırma, seri hale getirilmiş nesne
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"
}
]
}
]
}
]
}
http://jsonlint.com/ – tofutim
da json kontrol Kod yeniden biçimlendirildi – Thomas