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 8886947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:41:06+00:00 2026-06-14T21:41:06+00:00

I have an android/java task where I want to get JSON values into a

  • 0

I have an android/java task where I want to get JSON values into a String array to display in a ListView and I am not sure where to begin? Thanks.

private String[] values;
...
// this is what is returned from the web server (Debug view)
// jObj = {"success":1,"0":"Mike","1":"message 1","2":"Fred","3":"message 2","4":"John","5":"message 3"};

try {
   if (jObj.getInt("success") == 1) {
      .
      // what i'm trying to do here is iterate thru JObj and assign values to the 
      // values array to populate the ArrayAdapter so that the ListView displays this:
      //
      // Mike: Message 1
      // Fred: Message 2
      // John: Message 3
      //
      .
      this.setListAdapter(new ArrayAdapter<String>(
         this, android.R.layout.simple_list_item_1, android.R.id.text1, values));
      ListView listView = getListView();
   }
}
catch (JSONException e) {
   Log.e(TAG, e.toString());
}
  • 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-14T21:41:07+00:00Added an answer on June 14, 2026 at 9:41 pm

    Use ArrayList instead of Array to add values retrieved from Json Obejct and then set ArrayList for ListView as data-source. change your code as:

     ArrayList<String> array_list_values = new ArrayList<String>();
    try {
           if (jObj.getInt("success") == 1) {
    
            array_list_values.add(jObj.getString("0"));
            array_list_values.add(jObj.getString("1"));
            array_list_values.add(jObj.getString("2"));
            array_list_values.add(jObj.getString("3"));
            array_list_values.add(jObj.getString("4"));
            array_list_values.add(jObj.getString("5"));
            this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, array_list_values));
                    ListView listView = getListView();
                }
         }
    catch (JSONException e) {
          Log.e(TAG, e.toString());
      }
    

    EDIT :
    if number of messages is not always the same it may 1 to a larger number then you can Iterate JsonObject as:

     ArrayList<String> array_list_values = new ArrayList<String>();
    try {
           if (jObj.getInt("success") == 1) {
    
            Iterator iter = jObj.keys();
            while(iter.hasNext()){
            String key = (String)iter.next();
            String value = jObj.getString(key);
            array_list_values.add(value);
            }
    
    
            this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, array_list_values));
                    ListView listView = getListView();
                }
         }
    catch (JSONException e) {
          Log.e(TAG, e.toString());
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started programming a few weeks ago in java/android. I want to write
It seems the java.net.NetworkInterface implementation of android does not have a byte[] getHardwareAddress() method
I'm trying to integrate Facebook into my Android Java app, what I want it
I'm new to Android and Java. I have been working on my task i.e,
I already know quite a few tricks with Android java and I have an
I am new to Android and Java programming. I have a class which implements
I have to admit that I'm new to Java and Android. db4o seems to
I have an OpenCV Android app. Most of its code is in Java but
I am very new to Android development and Java. Have read around but I'm
I am creating an android application using Java. I have a boolean variable called

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.