次のJSON応答文字列をサーバーから変換しようとすると、このエラーが発生します。私はJSONObjectを返すか、JSONArrayを処理したいのですが、JSONArrayを返す時間はほとんどの場合、サーバーからの応答に依存します。JSONオブジェクトをJSON配列に変換できません
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)
誰も私を助けることができます。サーバー
jsonString = {"message":"No Results found!","status":"false"}
Javaコードから
JSONレスポンスは
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();
}
エラーログ以下の通りです。
おかげ
JsonArray列repsentationは、[」で始まります"とjsonObject startswith" {"にはもう少しの違いがありますので、googleにしてください – nafas