Possible Duplicate:
I have a nested data structure / JSON, how can access a specific value?
I have a JSON data that is in the below format. I need to get the store name corresponding to the one which has specialDeal as true in “Non Veg”. (NOTE: Only one of the stores will have specialDeal as true) How will i retrieve it. Please help. thanks in advance .. Please help me as i am just learning Java.
{"Food":
{
"Veg":
{
"amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
"discntType":"", "Store":"", "StoreType":"", "Fund":"",
"FundDetails":[
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
]
},
"Non Veg":
{
"chicken":
[
{
"amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
"discntType":"", "Store":"", "StoreType":"", "Fund":"",
"specialDeal":"", "promoStatus":"",
"FundDetails":[
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
]
},
{
"amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
"discntType":"", "Store":"", "StoreType":"", "Fund":"",
"specialDeal":"", "promoStatus":"",
"FundDetails":[
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
]
}
],
"fish":
[
{
"amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
"discntType":"", "Store":"", "StoreType":"", "Fund":"",
"specialDeal":"", "promoStatus":"",
"FundDetails":[
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
]
},
{
"amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
"discntType":"", "Store":"", "StoreType":"", "Fund":"",
"specialDeal":"", "promoStatus":"",
"FundDetails":[
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
{"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
]
}
],
"egg":
[
{
"amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
"discntType":"", "Store":"", "StoreType":"", "Fund":"",
"specialDeal":"", "promoStatus":"",
"discntVal":"", "FundVal":"", "FundBal":""
},
{
"amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
"discntType":"", "Store":"", "StoreType":"", "Fund":"",
"specialDeal":"", "promoStatus":"",
"discntVal":"", "FundVal":"", "FundBal":""
}
]
},
"isMember":"Y",
"orderId":""
}
You may try this :
since we are interested in only Non Veg part of the JSON, we can store it to some variable
i,e.
var nonVeg = jsonData.Food['Non Veg'];now we can say nonVeg as a object alone. in this object it has few more objects, so lets iterate through each one with for loop, and store it to a variable called
storeObj.since storeObj has many key-value parametres lets iterate each
storeObjwith for loop.and finally lets check whether the
specialDealproperty has a value oftrue? if yes thenconsole.logits ‘Store’ property i,e.storeObj['Store'].