【发布时间】:2016-07-25 08:49:54
【问题描述】:
以下是我的 Json 响应 -
CallWMDefaultWithRef1Response{CallWMDefaultWithRef1Result=[{"ROLE_NAME":"","USER_MOBILE":"","IMEI_NUMBER1":,"USER_ID":30,"ROLE_ID":4,"USER_NAME":""}]; }
下面是我的代码 -
if (resultlog!= null) {
try {
JSONArray resultarray = new JSONArray(resultlog);
for (int i = 0; i < resultarray.length(); i++) {
JSONObject c = resultarray.getJSONObject(i);
roleName = c.getString("ROLE_NAME");
userMobile = c.getString("USER_MOBILE");
imeiNumber = c.getString("IMEI_NUMBER1");
userId = c.getString("USER_ID");
roleid = c.getString("ROLE_ID");
userNmae = c.getString("USER_NAME");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
以下是我的错误
org.json.JSONException: 值 CallWMDefaultWithRef1Response 类型 java.lang.String 无法转换为 JSONArray
【问题讨论】:
-
首先检查你的 json 格式
-
“IMEI_NUMBER1”:缺少值
-
您能否在致电
new JSONArray(...)之前登录resultlog- 您似乎也没有为属性IMEI_NUMBER1指定值。 -
所有键和值都正确出现。我在我的问题中隐藏了峨眉山。否则所有的价值都来了……
-
这一行是否出现错误“JSONArray resultarray = new JSONArray(resultlog);”我认为您在这里不需要 JSONArray,它应该是“JSONObject”这样的 JSONObject result = new JSONObject(resultlog);