0

Вот ссылка на json http://www.mocky.io/v2/58c8523127000052192bb2aa

вот мой код

String finalJson = response.body().string();
Log.d(TAG_LOG, "AllResponse = " + finalJson);

try {
    JSONObject parentObject = new JSONObject(finalJson);
    JSONArray parentArray = parentObject.getJSONArray("orders");


    for (int i = 0; i <= parentArray.length(); i++) {
            JSONObject finalObject = parentArray.getJSONObject(i);



                        }`

как получить вот эти 2 аргумента из внутреннего массива {"orders":[ { "deliverytype": [ "walk", "car" ], }, { "deliverytype": [ "walk", "car" ], } ]}

2
  • 2
    А почему не пользуетесь Gson, если даже в тэгах его указали?
    – EgorD
    14 мар 2017 в 15:13
  • @EgorD я чуть изменил
    – Serg
    14 мар 2017 в 20:10

1 ответ 1

1
            JSONObject parentObject = new JSONObject(finalJson);
            JSONArray parentArray = parentObject.getJSONArray("orders");


            for (int i = 0; i < parentArray.length(); i++) {
                JSONArray childArray = parentArray.getJSONObject(i).getJSONArray("deliverytype");
                for (int j = 0; j < childArray.length(); j++) {
                    System.out.println(childArray.getString(j));
                }
            }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.