0

am parsing a json string. When i run my code am receiving json exception which says "type mismatch" at a point where am getting json array from json object. here is my code

String dataFromLogin="{"catego":{"id":"2","fname":"Tashen Jazbi","uname":"tashen",
    "password":"123","pic_url":"","lati":"33.7167","longi":"73.0667","city":"Islamabad",
    "country":"Pakistan","mobid":"000000000000000","street":"xyz",
    "dateandtime":"2013-12-29 18:07:52"}}";

try {
    JSONObject jsonObj = new JSONObject(dataFromLogin);
    //JSONObject response = jsonObj.getJSONObject("catego");
    JSONArray contacts = jsonObj.getJSONArray("catego");
    for (int i = 0; i < contacts.length(); i++) {
        JSONObject c = contacts.getJSONObject(i);

        fullname = c.getString("fname");

        uname = c.getString("uname");
        pic_url = c.getString("pic_url");

        lat = c.getString("lati");
        lng = c.getString("longi");

        city = c.getString("city");

        country = c.getString("country");

        street= c.getString("street");
    }

} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

I couldn't found where am doing wrong. If anyone can help then it'll be much appreciated.

Thanks :)

2 Answers 2

7
JSONArray contacts = jsonObj.getJSONArray("catego");

catego is a jsonobject

{ represents a json object node

[ represents a json array node

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

Comments

1

Use this:

JSONObject response = jsonObj.getJSONObject("catego");

because "catego" is an object not an array.

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.