Вы можете создать JSONObject Из строки как сильфонный
JSONObject jsonObject = new JSONObject(YOUR_JSON_STRING);
и разобрать jsonObject
JSONObject test1Json = jsonObject.getJSONObject("test1");
JSONObject oneTest1Json = test1Json.getJSONObject("1");
получить строковые значения
String action = oneTest1Json.getString("action");
String type = oneTest1Json.getString("type");
String id = oneTest1Json.getString("id");
Log.d("Json parse","action -"+action+" type -"+type+" id -"+id);
, если нужно их как JSONArray
вы можете попробовать
public JSONArray getJsonArray (JSONObject jsonObject){
JSONArray nameJsonArray = jsonObject.names();
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < nameJsonArray.length(); i++) {
try {
String key = nameJsonArray.getString(i);
jsonArray.put(jsonObject.getString(key));
} catch (JSONException e) {
e.printStackTrace();
}
}
return jsonArray;
}
в случае клавиш, как test1, test2, test3 ...
JSONObject jsonObject = new JSONObject("{'test1':'Kasun', 'test2':'columbo','test3': '29'}");
JSONArray jsonArray = new JSONArray();
for (int i = 1; i <= jsonObject.names().length(); i++) {
try{
jsonArray.put(jsonObject.getString("test" + i));
}catch (JSONException e){
e.printStackTrace();
}
вы можете получить свой JSONArray
таким образом.
Объясните свою проблему? – Emil
Ваш json неверен. – Manifest
Возможный дубликат [java итерации по JSONObject?] (Http://stackoverflow.com/questions/9151619/java-iterate-over-jsonobject) – Selvin