0

I am Using Retrofit v2.0.2. I am not able to get the JSON ResponseI am getting error like this okhttp3.ResponseBody$1@501040a,Please any one help me in this case.

This is Interface:

public interface IdeaInterface {

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

}

calling retrofit method here.

 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) {

            }
        });

This is my Base URL:

public class Constandapi {

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

my build.gradle which has retrofit library

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

Thanks in Advance.

demo
  • 672
  • 3
  • 9
  • 34

1 Answers1

-1

Retrofit code, in It am having Upload Model class.

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();
        }
    });

Here i have a model class, I am getting msg and stud_id as json objects

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;
}

}

Hop this will help you

Azim Shaikh
  • 589
  • 6
  • 18