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

  • Home
  • SEARCH
  • 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 8321233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:56:51+00:00 2026-06-08T22:56:51+00:00

I have a JSON string which is generated by a php file. The problem

  • 0

I have a JSON string which is generated by a php file. The problem is that the JSON string is not appearing on the textview of android. can anyone explain why?

public class AllUsersActivity extends ListActivity {

// Progress Dialog
private ProgressDialog pDialog;

// Creating JSON Parser object
JSONParser jParser = new JSONParser();

ArrayList<HashMap<String, String>> usersList;

// url to get all users list
private static String url_all_users = "http://10.0.2.2/android_connect/get_all_users.php";

// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_USERS = "users";
private static final String TAG_UID = "UserID";
private static final String TAG_FIRSTNAME = "FirstName";

// users JSONArray
JSONArray users = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.all_users);

    // Hashmap for ListView
    usersList = new ArrayList<HashMap<String, String>>();

    // Loading users in Background Thread
    new LoadAllusers().execute();

    // Get listview
    ListView lv = getListView();

    // on seleting single product
    // launching Edit Product Screen
    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // getting values from selected ListItem
            String uid = ((TextView) view.findViewById(R.id.uid)).getText()
                    .toString();

            // Starting new intent
            Intent in = new Intent(getApplicationContext(),
                    UserDetailsActivity.class);
            // sending uid to next activity
            in.putExtra(TAG_UID, uid);

            // starting new activity and expecting some response back
            startActivityForResult(in, 100);
        }
    });

}


/**
 * Background Async Task to Load all product by making HTTP Request
 * */
class LoadAllusers extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(AllUsersActivity.this);
        pDialog.setMessage("Loading users. Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    /**
     * getting All users from url
     * */
    protected String doInBackground(String... args) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = jParser.makeHttpRequest(url_all_users, "GET", params);

        // Check your log cat for JSON reponse
        Log.d("All users: ", json.toString());

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // users found
                // Getting Array of users
                users = json.getJSONArray(TAG_USERS);

                // looping through All users
                for (int i = 0; i < users.length(); i++) {
                    JSONObject c = users.getJSONObject(i);

                    // Storing each json item in variable
                    String id = c.getString(TAG_UID);
                    String name = c.getString(TAG_FIRSTNAME);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_UID, id);
                    map.put(TAG_FIRSTNAME, name);

                    // adding HashList to ArrayList
                    usersList.add(map);
                }
            } 
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all users
        pDialog.dismiss();
        // updating UI from Background Thread
        runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * Updating parsed JSON data into ListView
                 * */
                ListAdapter adapter = new SimpleAdapter(
                        AllUsersActivity.this, usersList,
                        R.layout.list_item, new String[] { TAG_UID,
                                TAG_FIRSTNAME},
                        new int[] { R.id.uid, R.id.name });
                // updating listview
                setListAdapter(adapter);
            }
        });

    }

}
}

this is the JSON string from the PHP file

{"Users":[{"0":[],"UserID":"1","FirstName":"lalawee","Email":"12345","Password":null},{"0":[],"UserID":"2","FirstName":"shadowblade721","Email":"12345","Password":null,"1":[]},{"0":[],"UserID":"3","FirstName":"dingdang","Email":"12345","Password":null,"1":[],"2":[]},{"0":[],"UserID":"4","FirstName":"solidsnake0328","Email":"12345","Password":null,"1":[],"2":[],"3":[]}],"success":1}
  • 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-08T22:56:52+00:00Added an answer on June 8, 2026 at 10:56 pm

    I’ve found the error.

    It is caused by case sensitiveness.

    users –> Users

    Mistake on my part. Sorry.

    Thanks for trying to help me!

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

Sidebar

Related Questions

I have a JSON string (external file) which has an element which can either
I have a C# method which generates a JSON string that Google charts requires.
I have a simple json string which contains a collection of objects http://sandapps.com/InAppAds/ads.json.txt When
I have web service which return json string like : d={main0ID:abc.es/main,main1ID:ah/main} I wanna append
I am getting JSON string from website. I have data which looks like this
I have a nested drag and drop list which return json formattet string. I
I have a method which requests external webservices and returns json here: public string
I have JSON string that has nested objects with dynamic names that vary each
I have a JSON string that I would like to include as a value
I have this string, which is generated by dojo.toJson() function: {page:accommodation task=viewList,language:undefined} When decoding

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.