我收到此錯誤,當我試圖從服務器轉換下面的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