我使用改造圖書館,使HttpClient的POST請求,但 我無法通過響應身體的JSONObject構造, 當我嘗試使用通過響應的JSONObject:unhandeled例外org.json.JSONObject
org.json.JSONObject Jobject = new org.json.JSONObject(jsonData);
我有以下異常:
unhandeled例外org.json.JSONObject
我的代碼:
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if(response.isSuccessful()){
String jsonData = response.body().toString();
JSONObject Jobject = new JSONObject(jsonData);
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
display_message.setText(t.toString());
}
});
從下面的語句預期的返回值:
String jsonData = response.body().source().toString();
是: {"is_new_user":true,"messing_user_data["mobile_number","country_code","password","pin"]}
但具體返回的結果是:
[size=90 text={"is_new_user":true,"messing_user_data":["mobile_number","countr…]
任何想法幫助我。
加上'的JSONObject Jobject = new JSONObject(jsonData);'在'try'塊內,並在catch塊中捕獲'JSONException'。 –
你可以寫日誌jsonData嗎?請檢查它是格式json文件嗎? JsonObject或JsonArray? – sonnv1368
請參閱上面其他更新 –