Skip to content Skip to sidebar Skip to footer

Json Array Not Showing All Values

I'm using JSONParser.java to show JSON data from a url the url and the data are correct, they show some values of JSON (more than one) but why this show only one value? ArrayList&

Solution 1:

Your JSON is invalid, there's an error in your line 22 at 3rd object of your array

"judul":"Article Four"",

Correct JSON is

{"status":"1","total":20,"artikel":[{"tanggal":"2013-08-07","judul":"Article One","kutipan":"Example of article quote..."},{"tanggal":"2013-07-23","judul":"Article Two","kutipan":"Example of article quote......"},{"tanggal":"2013-07-22","judul":"Article Three","kutipan":"Example of article quote......"},{"tanggal":"2013-03-16","judul":"Article Four","kutipan":"Exampleofarticlequote,..."}]}

Ok, Now you are getting Network related exception so, solution to this is, you've to use demo code like

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    newNetworkThread().execute();
}

classNetworkThreadextendsAsyncTask<Void, Void, Void> {


    @OverrideprotectedVoiddoInBackground(Void... voids) {

        ArrayList<HashMap<String, String>> artikelList = newArrayList<HashMap<String, String>>();
        JSONParser jParser = newJSONParser();
        JSONObject json = jParser.getJSONFromUrl(ArtikelURL);

        try {
            JSONArray artikels = json.getJSONArray("artikel");

            for(int i = 0; i < artikels.length(); i++){
                JSONObject c = artikels.getJSONObject(i);

                // Storing each json item in variableString tanggal = c.getString(TAG_TGL);
                String judul = c.getString(TAG_JUDUL);
                String kutipan = c.getString(TAG_KUTIPAN);

                HashMap<String, String> map = newHashMap<String, String>();
                map.put(TAG_TGL, tanggal);
                map.put(TAG_JUDUL, judul);
                map.put(TAG_KUTIPAN, kutipan);
                artikelList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        returnnull;
    }

    @OverrideprotectedvoidonPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);

    }
}

Don't forget to add this to AndroidManifest.xml file:

<uses-permissionandroid:name="android.permission.INTERNET"/>

Post a Comment for "Json Array Not Showing All Values"