我收到此错误,当我试图从服务器转换下面的JSON响应字符串。我想根据服务器的响应来处理JSONObject或JSONArray,因为大部分时间它返回JSONArray。从服务器JSON对象无法转换为JSON数组
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串repsentation开头“[ “和jsonObject startswith”{“有更多的课程差异,请谷歌它 – nafas