Error:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 2 column 1 path $
POJO:
LoginResponse {
@SerializedName("status")
private Integer status;
@SerializedName("message")
private String message;
@SerializedName("data")
private User user;
}
- Create Pojo class User details showing json object data Expected BEGIN_OBJECT but was STRING at line 2 column 1 path $
class User {
@SerializedName("id")
@Expose
private String id;
}
My Json Output like
{
"status": 1,
"message": "You are successfully logged in.",
"data": {
"id": "10",
"email": "abcdef@gmail.com",
"password": "3f009d72559f51e7e454b16e5d0687a1",
"mobile": "abc@gmail.com",
"verified_saller": "",
"first_name": "abc@gmail.com",
"middle_name": "abc@gmail.com",
"last_name": "abc@gmail.com",
"image": "",
"default_size": "0",
"wallet": "",
"status": "active",
"otp": "",
"updated": "2017-10-28 12:22:21",
"created": "2017-10-28 11:41:14"
}
}
create interface for retrofit Api parsing
@POST("user/login")
Call<LoginResponse> userLogIn(@Body User login);
Main Activity code below Expected BEGIN_OBJECT but was STRING at line 2 column 1 path $
APILogin service = ApiClient.getClient().create(APILogin.class); User login = new User(); login.setEmail(email); login.setPassword(password);
Call<User> userCall = service.userLogIn(login); userCall.enqueue(new Callback<User>() { @Override public void onResponse(Call<User> call, Response<User> response) { User user = response.body(); mRelativeLayout.setVisibility(View.GONE); mcardView.setVisibility(View.VISIBLE); //onSignupSuccess(); Log.d("onResponse", "" + response.body().getMessage()); if (response.body().getStatus() == 1) { Toast.makeText(LoginActivity.this, "" + response.body().getMessage(), Toast.LENGTH_SHORT).show(); Intent i = new Intent(LoginActivity.this, HomeActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(i); finish(); } else { Toast.makeText(LoginActivity.this, "" + response.body().getMessage(), Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(Call<User> call, Throwable t) { mRelativeLayout.setVisibility(View.GONE); mcardView.setVisibility(View.VISIBLE); call.cancel(); Toast.makeText(LoginActivity.this, "Please check your network connection and internet permission" + t.getMessage(), Toast.LENGTH_LONG).show(); Log.d("onFailure", t.toString()); } });