Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try like the following example: </p> <p><strong>MainActivity.java:</strong></p> <pre><code>package com.androidbegin.jsonparsetutorial; import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.widget.ListView; public class MainActivity extends Activity { // Declare Variables JSONObject jsonobject; JSONArray jsonarray; ListView listview; ListViewAdapter adapter; ProgressDialog mProgressDialog; ArrayList&lt;HashMap&lt;String, String&gt;&gt; arraylist; static String RANK = "rank"; static String COUNTRY = "country"; static String POPULATION = "population"; static String FLAG = "flag"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the view from listview_main.xml setContentView(R.layout.listview_main); // Execute DownloadJSON AsyncTask new DownloadJSON().execute(); } // DownloadJSON AsyncTask private class DownloadJSON extends AsyncTask&lt;Void, Void, Void&gt; { @Override protected void onPreExecute() { super.onPreExecute(); // Create a progressdialog mProgressDialog = new ProgressDialog(MainActivity.this); // Set progressdialog title mProgressDialog.setTitle("Android JSON Parse Tutorial"); // Set progressdialog message mProgressDialog.setMessage("Loading..."); mProgressDialog.setIndeterminate(false); // Show progressdialog mProgressDialog.show(); } @Override protected Void doInBackground(Void... params) { // Create an array arraylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); // Retrieve JSON Objects from the given URL address jsonobject = JSONfunctions .getJSONfromURL("http://www.androidbegin.com/tutorial/jsonparsetutorial.txt"); try { // Locate the array name in JSON jsonarray = jsonobject.getJSONArray("worldpopulation"); for (int i = 0; i &lt; jsonarray.length(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); 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")); // Set the JSON Objects into the array arraylist.add(map); } } catch (JSONException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void args) { // Locate the listview in listview_main.xml listview = (ListView) findViewById(R.id.listview); // Pass the results into ListViewAdapter.java adapter = new ListViewAdapter(MainActivity.this, arraylist); // Set the adapter to the ListView listview.setAdapter(adapter); // Close the progressdialog mProgressDialog.dismiss(); } } } </code></pre> <p><strong>JSON:</strong></p> <pre><code>{ "worldpopulation": [ { "rank": 1, "country": "China", "population": "1,354,040,000", "flag": "http://www.androidbegin.com/tutorial/flag/china.png" }, { "rank": 2, "country": "India", "population": "1,210,193,422", "flag": "http://www.androidbegin.com/tutorial/flag/india.png" }, { "rank": 3, "country": "United States", "population": "315,761,000", "flag": "http://www.androidbegin.com/tutorial/flag/unitedstates.png" }, { "rank": 4, "country": "Indonesia", "population": "237,641,326", "flag": "http://www.androidbegin.com/tutorial/flag/indonesia.png" }, { "rank": 5, "country": "Brazil", "population": "193,946,886", "flag": "http://www.androidbegin.com/tutorial/flag/brazil.png" }, { "rank": 6, "country": "Pakistan", "population": "182,912,000", "flag": "http://www.androidbegin.com/tutorial/flag/pakistan.png" }, { "rank": 7, "country": "Nigeria", "population": "170,901,000", "flag": "http://www.androidbegin.com/tutorial/flag/nigeria.png" }, { "rank": 8, "country": "Bangladesh", "population": "152,518,015", "flag": "http://www.androidbegin.com/tutorial/flag/bangladesh.png" }, { "rank": 9, "country": "Russia", "population": "143,369,806", "flag": "http://www.androidbegin.com/tutorial/flag/russia.png" }, { "rank": 10, "country": "Japan", "population": "127,360,000", "flag": "http://www.androidbegin.com/tutorial/flag/japan.png" } ] } </code></pre> <p><strong>Look at the following link for details:</strong></p> <p><a href="http://www.androidbegin.com/tutorial/android-json-parse-images-and-texts-tutorial/" rel="nofollow">Android JSON Parse Images and Texts Tutorial</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload