The reason it doesn't work is because your JSON data doesn't conform to the structure it would need to in order to deserialize into a DataSet. If you take a look at the example from the documentation, the data needs to be structured like this:
{
"table1" :
[
{
"column1" : "value1",
"column2" : "value2"
},
{
"column1" : "value3",
"column2" : "value4"
}
],
"table2" :
[
{
"column1" : "value1",
"column2" : "value2"
},
{
"column1" : "value3",
"column2" : "value4"
}
]
}
In other words, the outer object contains properties which represent tables. The property names correspond to the names of the tables, and the values are all arrays of objects where each object represents one row in the table. The objects' properties correspond to the column names, and their values are the row data. The row data values must be simple types such as string, int, bool, etc. (Arrays of simple types and nested data tables are also supported if you're using Json.Net 6.0 or later.)
Your JSON data is MUCH more complex than this, and is deeply nested. You will not be able to get Json.Net to deserialize it into a DataSet unless you write your own custom JsonConverter to do it. And I don't think it would be worth the effort to do so.
Instead, I would consider one of these other alternatives:
- Create a strongly-typed class hierarchy and deserialize into that. You can use json2csharp.com to help generate your classes. (Note, however, that json2csharp is not foolproof--sometimes you will need to edit the classes it generates to get things to work properly.)
- Deserialize into a
JObject
and use Json.Net's LINQ-to-JSON API to navigate and extract the data you need. Here is an example that might help with that. There are many other examples in the documentation as well as here on StackOverflow.
- Deserialize into a
dynamic
. This approach makes it pretty easy to get at your data, assuming you know its structure well, but you lose intellisense and compile-time checking.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…