adding to @Tawab Wakil's answer: If there are inner array's in your JSON like the following:
{
"rootNode": [
{
"id": 1,
"name": "testUser",
"attachedBag":
{
"content":
{
"items": [
{
"itemid": 322,
"itemName": "orange",
"price": 0.99,
"qty": 4
},
{
"itemid": 323,
"itemName": "apple",
"price": 0.49,
"qty": 5
}
]
},
"type": "subscriber"
}
}
]
}
and you wanted to get a list of items like "oranges", "apples", then you can do the following assuming your json is stored in a variable called "jsonResponse":
//"jsonResponse" contains the raw json as a string variable
var responseJsonObj = JsonNode.Parse(jsonResponse)?.AsObject();
var itemsList = responseJsonObj?["rootNode"]?.AsArray()[0]?["attachedBag"]?["content"]?["items"].AsArray();
var outputStrList = "";
foreach (var itemx in itemsList )
{
outputStrList += " - " + itemx.AsObject()["itemName"] + "\n";
}
//Output
// - orange
// - apple