samedi 27 juin 2015

How to write json reader if its more than one array?

Below is snipets of My json reader

    @Override
    protected Void doInBackground(Void... params) {
        // Create an array
        arraylist = new ArrayList<HashMap<String, String>>();
        // Retrieve JSON Objects from the given URL address
        jsonobject = JSONfunctions
                .getJSONfromURL("http://ift.tt/1ebqb1O");

        try {


            // Locate the array name in JSON
            jsonarray = jsonobject.getJSONArray("worldpopulation");

            for  (int i = 0; i < jsonarray.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                jsonobject = jsonarray.getJSONObject(i);
                // Retrive JSON Objects
                map.put("rank", jsonobject.getString("rank"));
                map.put("country", jsonobject.getString("country"));
                map.put("population", jsonobject.getString("population"));
                map.put("flag", jsonobject.getString("flag"));
                map.put("afakul", jsonobject.getString("afakul"));
                // Set the JSON Objects into the array
                arraylist.add(map);
            }
        } catch (JSONException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

And my json file is like this

{ 
"bingung":"apa",
"worldpopulation": 

    [

         {
         "rank":6,"country":"Pakistan",
         "population":"182,912,000",
                  "afakul":"amfunah"    ,

         "flag":"http://ift.tt/1kKjxlj"
         }, 

         {
         "rank":7,"country":"Nigeria",
         "population":"170,901,000",
 "afakul":"amfunJa ajajas ausjsjsushnah"    ,
         "flag":"http://ift.tt/1gnVIIk"
         }, 



    ],

}

I am confused at the "bingung" array ..how to read that array in json reader??????

Aucun commentaire:

Enregistrer un commentaire