-2

Is there anybody who knows that how can I get the string "num12" from this JSON array in android with JSONObject and JSONArray?

[{
"id": 7378,
"status": "publish",    
"acf": {
    "dars": [{
        "title": "math",
        "cat": "cat1",
        "kind": "free",
        "question": "num1"
    },{
        "title": "math2",
        "cat": "cat12",
        "kind": "free",
        "question": "num12"
    }]
}

}]

Bruno
  • 3,872
  • 4
  • 20
  • 37
Dura
  • 5
  • 5

1 Answers1

-1
  public String parseObj(JSONArray jsonArray) {
    int size = jsonArray.length();
    String question = "";
    try {
        for (int i = 0; i < size; i++) {
            JSONObject object = jsonArray.getJSONObject(0);
            JSONObject obj1 = object.getJSONObject("acf");
            JSONArray array = obj1.getJSONArray("dars");
            for (int j = 0; j < array.length(); j++) {
                JSONObject objectInner = jsonArray.getJSONObject(0);
                question = objectInner.getString("question");
            }

        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return question;
}
Stuti Kasliwal
  • 771
  • 9
  • 20