I am accessing a third-party vendors web service to obtain client data. The problem is, the JSON is not formatted within a consistently named hierarchy, making working with it very difficult. Here is a sample of the structure of the data:
{
"0": {
"account": {
"id": 97657
},
"warehouse": {
"sid": "9999"
},
"special": {
"value_one": "306"
}
},
"1": {
"account": {
"id": 97722
},
"warehouse": {
"sid": "9999"
},
"special": {
"value_one": "444"
}
},
"2": {
"account": {
"id": 88843
},
"warehouse": {
"sid": "9999"
},
"special": {
"value_one": "222"
}
},
"errno": 0,
"errmsg": "Operation completed with no errors"
}
I have tried numerous methods to parse through the data, but nothing is working. The only success I have had is by manually typing in the path, like such:
JObject objJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader));
string id = (string)objJson["0"]["account"]["id"];
string sid = (string)objJson["0"]["warehouse"]["sid"];
Trying anything dynamic throws error "Accessed JObject values with invalid key value: 0. Object property name expected."
for (int i = 0; i < objJson.Count; i++)
{
string id = (string)objJson[i]["account"]["id"];
}
UPDATE: Other questions of this type have a common parent. This one does not.