Problem :
I have a situation where an EAN API I'm using is returning inconsistent JSON, which I want to deserialize using JSON.NET.
In one case, it returns an object that contains objects and another another case returning only one object
Related posts Key Differences between XML and JSON
Sample Response :
{
"1":{
"0":{
"db_id":"12835424",
"title":"XXX"
},
"1":{
"db_id":"12768978",
"title":"YYY"
},
"2":{
"db_id":"12768980",
"title":"ZZZ"
},
}
}
And in another case, it returns an array of objects:
{
"2":[
{
"db_id":"12769199",
"title":"XXX"
},
{
"db_id":"12769200",
"title":"YYY"
},
{
"db_id":"12769202",
"title":"ZZZ"
},
]
}
I have no idea why this inconsistency exists, but this is the format I'm working with. What would be the correct way to deserialize both formats with the JsonConvert.DeserializeObject method?
Solution Fro this
This is something that should be possible by creating a JsonCreationConverter. This article can probably help out: http://dotnetbyexample.blogspot.nl/2012/02/json-deserialization-with-jsonnet-class.html
Source from :
http://stackoverflow.com/questions/10869314/json-net-deserialize-objects-within-object-array-of-objects
http://dotnetbyexample.blogspot.nl/2012/02/json-deserialization-with-jsonnet-class.html
I am happy My problem resolved .
I have a situation where an EAN API I'm using is returning inconsistent JSON, which I want to deserialize using JSON.NET.
In one case, it returns an object that contains objects and another another case returning only one object
Related posts Key Differences between XML and JSON
Sample Response :
{
"1":{
"0":{
"db_id":"12835424",
"title":"XXX"
},
"1":{
"db_id":"12768978",
"title":"YYY"
},
"2":{
"db_id":"12768980",
"title":"ZZZ"
},
}
}
And in another case, it returns an array of objects:
{
"2":[
{
"db_id":"12769199",
"title":"XXX"
},
{
"db_id":"12769200",
"title":"YYY"
},
{
"db_id":"12769202",
"title":"ZZZ"
},
]
}
I have no idea why this inconsistency exists, but this is the format I'm working with. What would be the correct way to deserialize both formats with the JsonConvert.DeserializeObject method?
Solution Fro this
This is something that should be possible by creating a JsonCreationConverter. This article can probably help out: http://dotnetbyexample.blogspot.nl/2012/02/json-deserialization-with-jsonnet-class.html
Source from :
http://stackoverflow.com/questions/10869314/json-net-deserialize-objects-within-object-array-of-objects
http://dotnetbyexample.blogspot.nl/2012/02/json-deserialization-with-jsonnet-class.html
I am happy My problem resolved .
Comments
Post a Comment