I'm using JSON.simple lib and try to parse a JSON response from HTTP GET. It works fine but I struggle decoding the following structure
"example": [
{
"param1": 4.88,
"param2": 60,
"param3": [
{
"param3_1": 501,
"param3_2": "Rain",
}
],
},
I manage to extract param1 and param2 successfully with following code:
JSONObject jo = (JSONObject) new JSONParser().parse(jsonString);
JSONArray ja;
Iterator<Map.Entry> itMap;
Iterator itArray;
ja = (JSONArray) jo.get("example");
if (ja != null) {
itArray = ja.iterator();
while (itArray.hasNext()) {
ExampleClass e = new ExampleClass();
itMap = ((Map) itArray.next()).entrySet().iterator();
while (itMap.hasNext()) {
Map.Entry pair = itMap.next();
switch (pair.getKey().toString()) {
case "param1":
e.param1 = (double)pair.getValue();
break;
case "param2":
e.param2 = (long)pair.getValue();
break;
case "param3":
.....
break;
default:
break;
}}}}
Does anyone know how to set up the iterator to get the param3 values?