1

I am trying to parse the response i get from the network database. I am getting only one value i.e. seller id in response. When i try to pass it in JSON Object, somehow the toast after it doesn't execute and the toast after it is not executed.

I know there are many related questions but i can't find whats wrong... please help. Thanks.

        try {

        JSONArray jArray = new JSONArray(stuff.toString());

        Toast.makeText(this, "len: " + jArray.length(), 1000).show(); // length is 1

        for (int i = 0; i < jArray.length(); i++) {
            Toast.makeText(this, "Arr: " + stuff, 1000).show(); 
                              // Arr: [{"seller_id":"5"}]

            JSONObject jObject = jArray.getJSONObject(i);
            j_id = jObject.getString(stuff);

                            // not getting executed
            Toast.makeText(this, "JSON: " + j_id, 1000).show();
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    Toast.makeText(this, "View: " + j_id, 1000).show(); // j_id is giving null value

This is my json data [{"seller_id":"5"}] i am trying to get the value of seller id (ie 5 here) out of it.

4
  • Is there an error for this? Commented Apr 8, 2013 at 6:16
  • 2
    Post your JSON data and from that what you are trying to get? Commented Apr 8, 2013 at 6:18
  • No there are no errors Commented Apr 8, 2013 at 6:26
  • First post your JSON code. So we could see where is your problem. Without it no one could help you. Commented Apr 8, 2013 at 6:35

2 Answers 2

2

There is a problem in jObject.getString() method args

JSONObject jObject = jArray.getJSONObject(i);
        j_id = jObject.getString(stuff);

Your giving the array. It should the name of the object i.e seller_id

so after the modification your code would be j_id = jObject.getString("seller_id");

Sign up to request clarification or add additional context in comments.

Comments

0

After the following code:

j_id = jObject.getString(stuff);

add textview.settext(j_id);

and change this textview with your textview name

and if its not working than show your complete json data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.