How do i traverse this json data in java?

Hi i want to traverse this json data using android fast networking library but i am not able to do so. Can someone please suggest a way to be able to fetch id and filename of all the objects in the array?

Note -It has to be done using ANDROID FAST NETWORKING LIBRARY -https://github.com/amitshekhariitbhu/Fast-Android-Networking

 [
          {
            "_id": "598ae8773376673353ef6da6",
            "filename": "nldcjjzpesyhkkx1502275703450.jpg",
            "votes": 33,
            "__v": 0
          },
          {
            "_id": "598ae83b3376673353ef6da5",
            "filename": "xlwkfcxicwhqibw1502275643486.jpg",
            "votes": 31,
            "__v": 0
          },
          {
            "_id": "598a2e7000c6717c3c04e534",
            "filename": "ndkiqptbifqmnjz1502228078447.jpg",
            "votes": 19,
            "__v": 0
          },
          {
            "_id": "5989ece9673738c027377710",
            "filename": "seicmgkzubzavfy1502211303478.jpg",
            "votes": 13,
            "__v": 0
          }
]

1 answer

  • answered 2017-08-12 09:42 Akhilesh Patil

    You can use GSON lib or you can retrieve using for loop like this:

    try {
        JSONArray jsonArray = new JSONArray(yourResponseStrOrJson);
        for(int i = 0; i < jsonArray.length(); i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Log.d("ID", jsonObject.getString("_id"));
            //TOTO retrive other element
        }
    }catch (JSONException e){
      e.printStackTrace();
    }