Json类型对象和数组不匹配

时间:2015-05-01 19:19:34

标签: android json

[

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

这是我的json。

我正在我的应用中检索这个,但它显示json不匹配。我知道我正在做对象和数组不匹配。

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

这是我的日志猫。

这是我的代码。如果我拿错了名字,也请告诉我。

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);

0 个答案:

没有答案