普通のJSONObject jsonResponse
では、私は単にboolean success = jsonResponse.getBoolean("success");
を使用します。今、私はRetrofitライブラリを使用する必要があります。 私は応答がGSON形式であることを知っています。だからこそ私のphp
ファイルの$response["success"]
をどう扱うかを考え出すのが苦労しているのです。Retrofit 2でJSON {"success":true}を読む方法は?
私はこの試みた:
call.enqueue(new Callback<User_Account_Model>() {
@Override
public void onResponse(Call<User_Account_Model> call, Response<User_Account_Model> response) {
try {
JSONObject jsonResponse = new JSONObject(new Gson().toJson(response));
boolean success = jsonResponse.getBoolean("success");
Toast.makeText(MainActivity.this,String.valueOf(success),Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
をしかし、何try and catch
内なのは実行されないようです。トーストメッセージは表示されません。私の方法は正しいのか何かが欠落しているのか、まったく間違っているのか?
'User_Account_Model'クラスを追加して、もしあればログも追加してください。 –
User_Account_Modelには、文字列の電子メールとパスワードのみが含まれています。ログにはトラブルシューティングに使用する重要な詳細は表示されません。 –