【发布时间】:2017-10-05 14:05:59
【问题描述】:
当我尝试从服务器转换以下 JSON 响应字符串时出现此错误。我想根据服务器的响应来处理 JSONObject 或 JSONArray,因为大多数时候它返回 JSONArray。
来自服务器的 JSON 响应
jsonString = {"message":"No Results found!","status":"false"}
Java代码如下
try
{
JSONArray jsonArrayResponse = new JSONArray(jsonString);
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
{
if(jsonArrayResponse != null && jsonArrayResponse.length() > 0)
{
getCancelPurchase(jsonArrayResponse.toString());
}
}
}
catch(JSONException e)
{
e.printStackTrace();
}
错误日志:
org.json.JSONException: Value {"message":"No Results found!","status":"false"} of type org.json.JSONObject cannot be converted to JSONArray
at org.json.JSON.typeMismatch(JSON.java:111)
at org.json.JSONArray.<init>(JSONArray.java:96)
at org.json.JSONArray.<init>(JSONArray.java:108)
谁能帮帮我。
谢谢
【问题讨论】:
-
JsonArray字符串表示以“[”开头和jsonObject以“{”开头当然还有更多区别,请google一下
标签: java android json jsonexception