java - Decode information from JSON Array within another JSON Array -
hello trying data json array in json array. trying parse but, unable it. json data.
{ "aggregate": "volume", "dimension1": "queries", "dimension2": "days", "results": [ { "id": 1998364102, "name": "denso", "data": {}, "values": [ { "id": "2015-05-23t00:00:00.000+0000", "name": "2015-05-23 00:00:00.0", "value": 5, "data": {} }, { "id": "2015-05-25t00:00:00.000+0000", "name": "2015-05-25 00:00:00.0", "value": 3, "data": {} }, { "id": "2015-05-21t00:00:00.000+0000", "name": "2015-05-21 00:00:00.0", "value": 9, "data": {} }, { "id": "2015-05-22t00:00:00.000+0000", "name": "2015-05-22 00:00:00.0", "value": 0, "data": {} }, { "id": "2015-05-19t00:00:00.000+0000", "name": "2015-05-19 00:00:00.0", "value": 7, "data": {} }, { "id": "2015-05-24t00:00:00.000+0000", "name": "2015-05-24 00:00:00.0", "value": 8, "data": {} }, { "id": "2015-05-20t00:00:00.000+0000", "name": "2015-05-20 00:00:00.0", "value": 15, "data": {} }, { "id": "2015-05-26t00:00:00.000+0000", "name": "2015-05-26 00:00:00.0", "value": 11, "data": {} } ] } ] }
how data "values" array? need value , name there. java code:
if (jsonobject.has("results")) { jsonarray jarray = jsonobject.getjsonarray("results"); (int = 0; < jarray.length(); i++) { jsonarray valuearray = new jsonarray(jarray.getjsonobject(i).getjsonarray("values")); (int j = 0; j < valuearray.length(); j++) { jsonobject name = valuearray.getjsonobject(j); system.out.println(j+"value:"+name.getint("value")); } } }
if (jsonobject.has("results")) { jsonarray jarray = jsonobject.getjsonarray("results"); while(jarray.iterator().hasnext()){ jsonobject valuearrayobject = ((jsonobject)jarray.iterator().next()); if(valuearrayobject.containskey("values")){ jsonarray valueobject = (jsonarray)valuearrayobject.get("values"); while(valueobject.iterator().hasnext()){ jsonobject valueobj = (jsonobject)valueobject.iterator().next(); system.out.println(valueobj.get("id")); } } } }
iterate on results array value array. have add exception handling parser error.
Comments
Post a Comment