2017-07-29 7 views
0

私はRetrofit v2.0.2を使用しています。私はJSON Responseを取得することができませんこののようなエラーが発生します[email protected]、この場合は誰も助けてください。改造バージョン2.0.2でJsonレスポンスを取得するには?

これはインタフェースです:

public interface IdeaInterface { 

    /*Get zoontype for registeration*/ 
    @GET("api/user/get_zone") 
    Call<ResponseBody> display(); 

} 

は、ここでは改造メソッドを呼び出します。

public void Get_Zoontype() 
    { 
     reg_progressbar.setVisibility(View.VISIBLE); 

     /* RestAdapter adapter = new RestAdapter.Builder() 
       .setEndpoint(Constandapi.ROOT_URL) //Setting the Root URL 
       .build();*/ 
     // Retrofitnew Retrofit.Builder(); 

     Retrofit adapter = new Retrofit.Builder() 
       .baseUrl(Constandapi.ROOT_URL) 
       .build(); 

     IdeaInterface report = adapter.create(IdeaInterface.class); 

     Call<ResponseBody> call = report.display(); 

     call.enqueue(new Callback<ResponseBody>() { 
      @Override 
      public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { 

        Log.d("reponcevalues","**** "+response.toString()); 
      } 

      @Override 
      public void onFailure(Call<ResponseBody> call, Throwable t) { 

      } 
     }); 

これは私のベースのURLです:換装ライブラリに事前に

compile 'com.squareup.retrofit2:retrofit:2.0.2' 
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1' 

おかげを持ち

public class Constandapi { 

    public static final String ROOT_URL = "http://vehiclerescue.in/ideadarpan_beta/"; 
} 

私のbuild.gradle。

+0

https://stackoverflow.com/question/37589588/retrofit-get-string-response –

+0

@NaveenKumar私のコードはあなたの答えと同じではないとは思わない – Mariyappan

+1

このコードを使用してログを出力するresponse.body()。string()ins tead response.toString() –

答えて

-1

アップロードモデルのクラスがあります。ここで

Call<Uploads> uploadsCall = service.profilePicUpload(body, id); 
    uploadsCall.enqueue(new Callback<Uploads>() { 
     @Override 
     public void onResponse(Call<Uploads> call, Response<Uploads> response) { 
      response.body(); 
      if (response.isSuccessful()) { 
       String s = response.body().getMsg(); 
       Communicate.showToast(MyAccountActivity.this, s); 
       ImageHelper.getImage(MyAccountActivity.this, AppController.ProficPic + profpic, profilePic, 
         R.drawable.ic_user, R.drawable.ic_user, new ImageHelper.Callback() { 
          @Override 
          public void Success() { 
           runOnUiThread(new Runnable() { 
            @Override 
            public void run() { 
             profpicProgress.setVisibility(View.GONE); 
            } 
           }); 
          } 
          @Override 
          public void Error() { 
           runOnUiThread(new Runnable() { 
            @Override 
            public void run() { 
             profpicProgress.setVisibility(View.GONE); 
            } 
           }); 
          } 
         }); 
      } else { 
       Communicate.showToast(MyAccountActivity.this, "please try again"); 
       profpicProgress.setVisibility(View.GONE); 
      } 
     } 

     @Override 
     public void onFailure(Call<Uploads> call, Throwable t) { 
      profpicProgress.setVisibility(View.GONE); 
      Communicate.showToast(MyAccountActivity.this, "error"); 
      Log.e(AppController.TAG, "onFailure: " + t.getLocalizedMessage()); 
      Log.e(AppController.TAG, "onFailure: " + t.getMessage()); 
      t.printStackTrace(); 
     } 
    }); 

私はこれがあなたを助けるモデルクラスは、私はmsgとstud_idを取得していますJSONは

public class Uploads { 
@SerializedName("msg") 
@Expose 
private String msg; 

@SerializedName("stud_id") 
@Expose 
private String stud_id; 

public String getMsg() { 
    return msg; 
} 

public void setMsg(String msg) { 
    this.msg = msg; 
} 

public String getStud_id() { 
    return stud_id; 
} 

public void setStud_id(String stud_id) { 
    this.stud_id = stud_id; 
} 

}

ホップをオブジェクトとして持って

関連する問題