0

[

{
    "id":"20",
    "name":"sinha",
    "city":"new",
    "zone":"",
    "area":"delhi",
    "mobile":"9716515438",
    "address":"9716515438",
    "reg_date":"2015-02-28 20:29:10"
},

this is my json.

i am retrieving this in my app, but it shows json mismatch. i know i am doing object and array mismatch.

at org.json.JSON.typeMismatch(JSON.java:111) 
at org.json.JSONObject.<init>(JSONObject.java:159)
at org.json.JSONObject.<init>(JSONObject.java:172)

this is my log cat.

and this is my code. also please let me know if i am taking the name of anything wrong.

private static final String TAG_CONTACTS = " ";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_CITY = "city";
private static final String TAG_ZONE = "zone";
private static final String TAG_AREA = "area";
private static final String TAG_MOBILE = "mobile";
private static final String TAG_REG_DATE = "reg_date";
JSONArray json_array = null;
ServiceHandler sh = new ServiceHandler();


        String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);

        Log.d("Response: ", "> " + jsonStr);

        if (jsonStr != null) {
            try {
                JSONObject jsonObj = new JSONObject(jsonStr);


                json_array = jsonObj.getJSONArray(TAG_CONTACTS);


                for (int i = 0; i < json_array.length(); i++) {
                    JSONObject c = json_array.getJSONObject(i);

                    String name = c.getString(TAG_NAME);
                    String id = c.getString(TAG_ID);
                    String city = c.getString(TAG_CITY);
                    String zone = c.getString(TAG_ZONE);
                    String area = c.getString(TAG_AREA);
                    String mobile = c.getString(TAG_MOBILE);
                    String date = c.getString(TAG_REG_DATE);

1 Answer 1

1

The error includes a line indicating where the error happened. You should indicate where the line is on your question.

Also, put the complete JSONArray that is failing, since you are using a JSONArray but your example contains only one JSONObject element, without the brackets opening/closing it.

Maybe that could be your error, since you are trying to put:

{
    "id":"20",
    "name":"sinha",
    "city":"new",
    "zone":"",
    "area":"delhi",
    "mobile":"9716515438",
    "address":"9716515438",
    "reg_date":"2015-02-28 20:29:10"
},

As a json array and it is a JSONObject

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

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.