I have to fetch the value from array "machines" having nested data and need to fetch for "value1": "Need to fetch this value". Tried a lot of code but still not able to fetch the same.
{
"name":"anyname",
"machines":[
{
"id":"771760",
"type":"general",
"properties":{
"value1":"1",
"value2":"2"
}
},
{
"id":"341256",
"type":"general",
"properties":{
"value1":"Need to fetch this value"
}
},
{
"id":"341256",
"type":"general",
"properties":{
"value1":"1",
"value2":"2"
}
}
]
}
Tried using JsonObject and JsonArray, Still not worked
public String getValueForAnyKeyHavingNestedObjects(String jsonData,String outerObjectKey, String keyWhoseValueToFetch) throws JSONException {
JSONObject obj = new JSONObject(jsonData);
String value = String.valueOf(obj.getJSONObject(outerObjectKey).get(keyWhoseValueToFetch));
return value;
}
jacksonorgsonto help you with this? Or it's a requirement not to use any json libraries?