I cant parse json string. This is only json object, i cant barse its. I use iterator
like this:
JSONObject jsonObject = new JSONObject("test1");
Iterator<String> iterator = jsonObject.keys();
while(iterator.hasNext()) {
String currentKey = iterator.next();
JSONObject obj = jsonObject.optJSONObject(currentKey);
if (obj != null) {
Iterator<String> iterator2 = obj.keys();
Log.e("Iterator 2", iterator2.toString());
}
}
But i have error: `org.json.JSONException: Value sensorTypes of type java.lang.String cannot be converted to JSONObject. My json string:
{ "test1": {
"1": {
"action": "0",
"type": "1",
"id": "1",
},
"2": {
"action": "0",
"type": "1",
"id": "2",
}
},
"test2": {
"1": {
"id": "1",
"name": "one"
},
"2": {
"id": "2",
"name": "two"
},
"5": {
"id": "5",
"name": "three"
}
}}
How i can parse json like this?