I\'ve been trying to parse a block of json using json.net (https://dl.dropboxusercontent.com/u/2976553/json) but it fails stating that there is text after the json object.
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:
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.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.