我在我的android应用中使用了改造,我有一个登录api,当我从Postman测试它时它可以正常工作。但是,当我从我的应用程序对其进行测试时,它返回预期的BEGIN_OBJECT,但位于第2行第1列路径$ 错误。我在另一个活动中使用了具有相同参数的相同api,并且在那儿工作正常。对于发生了什么问题,我真的一无所知。
我的JSON参数
{
"device_token":"device token",
"facebook_id":"1970665",
"ur_address":"342 Brooklyn Road",
"ur_category":"0",
"ur_city":"Holly Pond",
"ur_country":"US",
"ur_email":"abc@gmail.com",
"ur_gender":"female",
"ur_latitude":"34.1786998",
"ur_longitude":"-86.6154153",
"ur_name":"User name",
"ur_photo":"http://graph.facebook.com/1970665/picture?type=large",
"ur_range":"50"
}
我的模型班
public class LoginBody {
@SerializedName("facebook_id")
@Expose
private String facebookId;
@SerializedName("ur_name")
@Expose
private String urName;
@SerializedName("ur_email")
@Expose
private String urEmail;
@SerializedName("ur_gender")
@Expose
private String urGender;
@SerializedName("ur_photo")
@Expose
private String urPhoto;
@SerializedName("ur_range")
@Expose
private String urRange;
@SerializedName("ur_category")
@Expose
private String urCategory;
@SerializedName("ur_latitude")
@Expose
private String urLatitude;
@SerializedName("ur_longitude")
@Expose
private String urLongitude;
@SerializedName("ur_city")
@Expose
private String urCity;
@SerializedName("ur_country")
@Expose
private String urCountry;
@SerializedName("ur_address")
@Expose
private String urAddress;
@SerializedName("device_token")
@Expose
private String deviceToken;
/**
* No args constructor for use in serialization
*
*/
public LoginBody() {
}
/**
*
* @param urCategory
* @param urCountry
* @param deviceToken
* @param urAddress
* @param facebookId
* @param urName
* @param urCity
* @param urEmail
* @param urLongitude
* @param urGender
* @param urLatitude
* @param urRange
* @param urPhoto
*/
public LoginBody(String facebookId, String urName, String urEmail, String urGender, String urPhoto, String urRange, String urCategory, String urLatitude, String urLongitude, String urCity, String urCountry, String urAddress, String deviceToken) {
super();
this.facebookId = facebookId;
this.urName = urName;
this.urEmail = urEmail;
this.urGender = urGender;
this.urPhoto = urPhoto;
this.urRange = urRange;
this.urCategory = urCategory;
this.urLatitude = urLatitude;
this.urLongitude = urLongitude;
this.urCity = urCity;
this.urCountry = urCountry;
this.urAddress = urAddress;
this.deviceToken = deviceToken;
}
public String getFacebookId() {
return facebookId;
}
public void setFacebookId(String facebookId) {
this.facebookId = facebookId;
}
public String getUrName() {
return urName;
}
public void setUrName(String urName) {
this.urName = urName;
}
public String getUrEmail() {
return urEmail;
}
public void setUrEmail(String urEmail) {
this.urEmail = urEmail;
}
public String getUrGender() {
return urGender;
}
public void setUrGender(String urGender) {
this.urGender = urGender;
}
public String getUrPhoto() {
return urPhoto;
}
public void setUrPhoto(String urPhoto) {
this.urPhoto = urPhoto;
}
public String getUrRange() {
return urRange;
}
public void setUrRange(String urRange) {
this.urRange = urRange;
}
public String getUrCategory() {
return urCategory;
}
public void setUrCategory(String urCategory) {
this.urCategory = urCategory;
}
public String getUrLatitude() {
return urLatitude;
}
public void setUrLatitude(String urLatitude) {
this.urLatitude = urLatitude;
}
public String getUrLongitude() {
return urLongitude;
}
public void setUrLongitude(String urLongitude) {
this.urLongitude = urLongitude;
}
public String getUrCity() {
return urCity;
}
public void setUrCity(String urCity) {
this.urCity = urCity;
}
public String getUrCountry() {
return urCountry;
}
public void setUrCountry(String urCountry) {
this.urCountry = urCountry;
}
public String getUrAddress() {
return urAddress;
}
public void setUrAddress(String urAddress) {
this.urAddress = urAddress;
}
public String getDeviceToken() {
return deviceToken;
}
public void setDeviceToken(String deviceToken) {
this.deviceToken = deviceToken;
}
@Override
public String toString() {
return new ToStringBuilder(this).append("facebookId", facebookId).append("urName", urName).append("urEmail", urEmail).append("urGender", urGender).append("urPhoto", urPhoto).append("urRange", urRange).append("urCategory", urCategory).append("urLatitude", urLatitude).append("urLongitude", urLongitude).append("urCity", urCity).append("urCountry", urCountry).append("urAddress", urAddress).append("deviceToken", deviceToken).toString();
}
}
Api界面
@POST("login")
@Headers("Content-Type:application/json")
Call<LoginData> loginUser(@Body LoginBody loginBody);
邮递员回复
{
"status": 1,
"message": "success",
"user": {
"ur_id": "4",
"facebook_id": "1970665",
"ur_name": "User name",
"ur_email": "abc@gmail.com",
"ur_latitude": "34.1786998",
"ur_longitude": "-86.6154153",
"ur_city": "Holly Pond",
"ur_country": "US",
"ur_gender": "0",
"ur_range": "494",
"ur_sub_status": "0",
"created_at": "2017-12-01 18:15:41",
"ur_address": "342 Brooklyn Road",
"ur_photo": "http://graph.facebook.com/1970665/picture?type=large",
"ur_device_token": "device token"
}
}
答案 0 :(得分:0)
请放入响应,他在这里说:“我期望响应中的某个值是一个对象,但我找到了一个字符串”。
例如预期:
"key" : {
"inner_key" : "value"
}
发现:
"key" : "value"