I have a JSON as folows
{
"Root1": {
"Result": {
"ID": "200",
"Text": "OK"
}
}
}
Is there any way I can able to extract the values of "ID" to a variable directly without traversing through the root element i.e. "Root1". Because the root element name will change each time I run the application like "Root2", "Root3".
Below is the code in which I am trying to extract the ID with "Root1" and "Result" element
JSONObject jsonObject = new JSONObject("{\"Root1\": {\"Result\": {\"ID\": \"200\",\"Text\": \"OK\"}}}");
String element = jsonObject.getJSONObject("Root1").getJSONObject("Result").getString("ID");