How to loop thru items in Json string - JArray not working for me

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

Guest
I have a Json string and I need to loop thru the elements. For example, here's a small snippet:

{[
{
"Items": [
{
"v_id": "14",
"v_type": "ConceptItem",
"attributes": {
"name": "Chevrolet Camaro ZL1",
"description": ""
}
},
{
"v_id": "11",
"v_type": "ConceptItem",
"attributes": {
"name": "OnePlus 8 Pro",
"description": ""
}
}
]
},
{
"@@edgeEvents": [
{
"e_type": "EvalEvent_Has_ConceptItem",
"from_id": "2703",
"from_type": "EvalEvent",
"to_id": "15",
"to_type": "ConceptItem",
"directed": true,
"attributes": {
"IsChosen": false
}
},
{
"e_type": "EvalEvent_Has_ConceptItem",
"from_id": "2703",
"from_type": "EvalEvent",
"to_id": "12",
"to_type": "ConceptItem",
"directed": true,
"attributes": {
"IsChosen": true
}
}
]
}
]}

If I convert this to a JArray, it will have 2 items:
"Items" and "@@edgeEvents".

OK, but those have arrays of data that I need to loop through. It would be nice if I could do something like:

foreach var item in Json["Item"]
{
someClass.v_Id = item.v_Id;
ect...
}

foreach var item in Json["@@edgeEvents"]
{
someClass.e_type = item.e_type;
ect...
}

Any recommendations? Thank you.

Continue reading...
 
Back
Top