这是场景......
我收到邮递员的回复,如下所示
{
"success": 1,
"username": "anuj@Cmail.com",
"password": "123456",
"userid": "1121",
"pass": "123456",
"email": "anuj@Cmail.com",
"mobile": "902430000",
"name": "Anuj"
}
和我的pojo类如下(也有构造函数和getter setter)
public class LoginPojo {
@SerializedName("success")
@Expose
private int success;
@SerializedName("username")
@Expose
private String username;
@SerializedName("password")
@Expose
private String password;
@SerializedName("userid")
@Expose
private String userid;
@SerializedName("pass")
@Expose
private String pass;
@SerializedName("email")
@Expose
private String email;
@SerializedName("mobile")
@Expose
private String mobile;
@SerializedName("name")
@Expose
private String name;
}
创建休息适配器就像
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://theuroguard.in/")
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
serverApi=retrofit.create(ServerApi.class);
**我的界面就像**
public interface ServerApi {
@FormUrlEncoded
@POST("/mobile/user_login")
Call<LoginPojo> user_login(
@Field("username") String username,
@Field("password") String password,
@Field("token") String token
);
}
并按以下方式调用..
serverApi.user_login(smail,spassword,token).enqueue(new Callback<LoginPojo>() {
@Override
public void onResponse(Call<LoginPojo> call, Response<LoginPojo> response) {
Toast.makeText(MainActivity.this, ""+response.message().toString(), Toast.LENGTH_SHORT).show();
Log.e("login error",response.message().toString());
dismiss_dialogue();
}
@Override
public void onFailure(Call<LoginPojo> call, Throwable t) {
dismiss_dialogue();
Log.e("login error",t.getMessage().toString());
Toast.makeText(MainActivity.this, ""+t.getMessage().toString(), Toast.LENGTH_SHORT).show();
}
});
}
我不明白为什么我会吮吸错误: java.lang.IllegalStateException:预期为BEGIN_OBJECT,但在第1行第1行路径为STRING
我需要改变,请协助