R
R
rafaelSalihov2020-09-05 06:21:35
Java
rafaelSalihov, 2020-09-05 06:21:35

How to parse this json?

json itself json link

with this code brought out what is in "def" , but I need it in "tr" I can't get it how to do it?

public void getJson() throws Exception {




    String post_id = null; 

    JSONObject obj = new JSONObject(getJsonN());




    JSONArray phoneNumbersArr = (JSONArray) obj.get("def");

    for (int i = 0; i < phoneNumbersArr.length(); i++) {
        post_id = phoneNumbersArr.getJSONObject(i).getString("text");
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Araya, 2020-09-05
@Araya

((JSONObject)((JSONArray)object.get("def")).get(0)).get("tr")

the fastest and easiest way. If a specific "tr" is needed, then this can be cast into a JSONArray again

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question