I have a json url link which i would like to read its json response and extract values into variables so that i can use them later
{
"responseHeader": {
"status": 0,
"QTime": 4,
"params": {
"q": "*:*",
"facet.field": "TESTARRAY",
"indent": "true",
"rows": "0",
"wt": "json",
"facet": "true"
}
},
"response": {
"numFound": 12,
"start": 0,
"docs": []
},
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"TESTARRAY": [
"JON",
22,
"SMITH",
34,
"ROBERT",
12
]
},
"facet_dates": {},
"facet_ranges": {},
"facet_intervals": {}
}
}
For extraction,I am using
JSONObject obj = new JSONObject(IOUtils.toString(new URL(jsonlink), Charset.forName("UTF-8")));
JSONArray arr = obj.getJSONArray("TEST_ARRAY");
Integer smithage=arr.get("SMITH");
So far this approach is not working. What would be the best way to deal with it Thanks in advance