I'm trying to parse JSON into an array that is formatted like the following:
{
"company": [
[
{
"id": 1,
"name": "Test Company1"
},
{
"id": 2,
"name": "Test Company2"
}
]
]
}
I'm using Newtonsoft JObjects to do this. I have the following code so far, which gets me to the "company" object:
JObject joResponse = JObject.Parse(json);
JArray arr = (JArray)joResponse["company"];
But there is only one value in the array, it's one single value with the all of the JSON nodes in it:
[
{
"id": 1,
"name": "Test Company1"
},
{
"id": 2,
"name": "Test Company2"
}
]
So essentially I need to get to that 2nd level, but the 2nd level inside of "company" isn't named so I'm not sure how to access it.
JArray arr = (JArray)joResponse["company"][0]company, for unknown reasons, contains a nested array, you needarr[0][0]["name"],arr[0][1]["id"]etc. -- Are you sure this JSON is correct?JArray arr = (JArray)joResponse["company"][0]did the trick, thank you! The JSON comes from an API that we do not own, so I'm not sure why they created it with a nested array so that was I was trying to work around. There should be only ever one "company" array in the nest so using [0] should work perfect.