Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:39:01+00:00 2026-06-13T00:39:01+00:00

Possible Duplicate: JSON object to listView i have a json data on server and

  • 0

Possible Duplicate:
JSON object to listView

i have a json data on server and want to retrive it and show it in my android listview..sorry if this is duplicate question please give me some suggestion to start from stratch

answer will be appreciated thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:39:03+00:00Added an answer on June 13, 2026 at 12:39 am

    This may help you..

    Your Actmain class

    Actmain.java

    public class Actmain extends Activity {
    
    // url to make request
    private static String url = "http://api.androidhive.info/contacts/";
    
    // JSON Node names
    private static final String TAG_CONTACTS = "contacts";
    private static final String TAG_ID = "id";
    private static final String TAG_NAME = "name";
    private static final String TAG_EMAIL = "email";
    private static final String TAG_ADDRESS = "address";
    private static final String TAG_GENDER = "gender";
    private static final String TAG_PHONE = "phone";
    private static final String TAG_PHONE_MOBILE = "mobile";
    private static final String TAG_PHONE_HOME = "home";
    private static final String TAG_PHONE_OFFICE = "office";
    private ArrayList<HashMap<String, String>> _alistHashmap; 
    private Clsgetjson getjson;
    
    // contacts JSONArray
    private JSONArray Jarray = null;
    private JSONObject jobj;
    private Listview lv;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
    // Creating JSON Parser instance
    getjson = new Clsgetjson();
    
     _alistHashmap = new ArrayList<HashMap<String, String>>();
    
    lv=(listview)findviewbyid(R.id.lv);
    
    
     jobj= getjson.getJSONFromUrl(url);
    
    
    
      try {
            // Getting Array of Contacts
            Jarray = json.getJSONArray(TAG_CONTACTS);
    
            // looping through All Contacts
            for(int i = 0; i < contacts.length(); i++){
                JSONObject jobject = Jarray.getJSONObject(i);
    
                // Storing each json item in variable
                String id = jobject.getString(TAG_ID);
                String name = jobject.getString(TAG_NAME);
                String email = jobject.getString(TAG_EMAIL);
                String address = jobject.getString(TAG_ADDRESS);
                String gender = jobject.getString(TAG_GENDER);
    
                // Phone number is agin JSON Object
                JSONObject phone = jobject.getJSONObject(TAG_PHONE);
                String mobile = phone.getString(TAG_PHONE_MOBILE);
                String home = phone.getString(TAG_PHONE_HOME);
                String office = phone.getString(TAG_PHONE_OFFICE);
    
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
    
                // adding each child node to HashMap key => value
                map.put(TAG_ID, id);
                map.put(TAG_NAME, name);
                map.put(TAG_EMAIL, email);
                map.put(TAG_PHONE_MOBILE, mobile);
    
                // adding HashList to ArrayList
                contactList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    
    
    
        //now set your adapter to listview (you can do this under buttons onclick event)
    
    
    String[] from=new String[] { TAG_NAME, TAG_EMAIL, TAG_PHONE_MOBILE };
    int[] to= new int[] {R.id.name, R.id.email, R.id.mobile }
    
    SimpleAdapter adapter = new SimpleAdapter(this, contactList,
                R.layout.raw_lv,from,to);
    
    lv.setAdapter(adapter);
    

    now Clsgetjson.java

    public class Clsgetjson {
    
    
    static JSONObject jObj = null;
    static String strjson = "";
    
    
    public JSONObject getJSONFromUrl(String url) {
    
        // Making HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
    
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
    
    strjson=EntityUtility.toString(httpEntity);
    
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    
    
        // try parse the string to a JSON object
        try {
    
    
            jObj = new JSONObject(strjson);
    
    
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
    
        // return JSON String
        return jObj;
    
    }
    }
    

    or with parameter

            List<NameValuePair> nvp = new ArrayList<NameValuePair>(2);
        nvp.add(new BasicNameValuePair("function", "login"));
        nvp.add(new BasicNameValuePair("uname", username));
        nvp.add(new BasicNameValuePair("pwd", pass)));
    

    add this in request

            if(nvp!=null)
    
            hpost.setEntity(new UrlEncodedFormEntity(nvp));
    

    everything else is same as above

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to parse JSON in JavaScript I have this JSON string: [{title:
Possible Duplicate: Getting JavaScript object key list How to iterate json data in jquery
Possible Duplicate: Loop through Json object { data: [ { name: Jen, id: 1
Possible Duplicate: JSON Array iteration in Android/Java I am fetching JSON string from server
Possible Duplicate: How do I access this object property? The data returned in a
Possible Duplicate: Dynamic object property name $.ajax({ url: ranktonumber.json, dataType: json, success: function (data)
Possible Duplicate: Dynamic object property name I have an object like this var localAppConfig
Possible Duplicate: How to parse JSON easily? I have this string: [{text: 'First Option',
Possible Duplicate: Serializing to JSON in jQuery Convert Object to JSON string I want
Possible Duplicate: Convert JS object to JSON string I have a JSON object in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.