I am having JSON structure like this
"line_items":[
{
"id":385,
"name":"AD737",
"product_id":743,
"variation_id":0,
"quantity":2,
"sku":"TH99533",
"price":0,
"parent_name":null,
"composite_parent":"",
"composite_children":[
386
],
"bundled_by":"",
"bundled_item_title":"",
"bundled_items":[
]
},
{
"id":386,
"name":"Arisun AD737 (Set of 8)",
"product_id":742,
"variation_id":0,
"quantity":2,
"sku":"TH99533-8",
"price":2400,
"parent_name":null,
"composite_parent":385,
"composite_children":[
],
"bundled_by":"",
"bundled_item_title":"",
"bundled_items":[
387
]
},
{
"id":387,
"name":"Set of 8",
"product_id":738,
"variation_id":0,
"quantity":16,
"sku":"TH99533-1",
"price":0,
"parent_name":null,
"composite_parent":"",
"composite_children":[
],
"bundled_by":386,
"bundled_item_title":"Set of 8",
"bundled_items":[
]
}
]
the tree nodes are interlinked
I want to pickout the quantity from third block but for that i have to traverse from 1 to 2 and with the help of 2 i have to get quantity in third block.
- From First i have to get the composite_children //386
- With this i have to get the bundled_items from second //387
- with the id got from 2 I have to get the quantity // 16
I tried in this way
Set<Object> compositeChildernId= new Set<Object>();
for(Object LineItem:lstMetaData){
Map<String,Object> MapLineItems= (Map<String, Object>)LineItem;
for(String MapLineItem : MapLineItems.keyset()){
if( MapLineItem == 'composite_children'){
List<Object> tempObjMap = (List<Object>) MapLineItems.get('composite_children');
if( tempObjMap.size()>0){
compositeChildernId.addAll(tempObjMap);
}
}
}
}
with the above i can get only the composite_children id like parentComponentID >>>{386, 389, 392, 400}
but not able to traverse through the next loop