当我试图反序列化这个json:
{
"Token": "",
"Error": "Invalid Username or Password",
"Location": null
}
我收到了一个错误:
10-06 14:51:26.310: DEBUG/LoginActivity(18676): JsonParseException: Expecting object found: "{\"Token\":\"\",\"Error\":\"Invalid Username or Password\",\"Location\":null}"
我的代码:
LoginResult loginResult = new Gson().fromJson(responseContent, LoginResult.class);
public class LoginResult {
@SerializedName("Token")
private String token;
@SerializedName("Error")
private String error;
@SerializedName("Location")
private Location location;
public String getToken() {
return token;
}
public String getError() {
return error;
}
public Location getLocation() {
return location;
}
public class Location {
@SerializedName("AssignmentID")
private String assignmentID;
@SerializedName("LocationName")
private String locationName;
@SerializedName("Brand")
private String brand;
@SerializedName("Address")
private String address;
@SerializedName("Information")
private String information;
}
}
有什么建议吗?
答案 0 :(得分:0)
我在Google上查找了您的错误,发现错误吐出this text:
[{"status":"ikas","nid":16,"name":"Mu","year": 2005,"type":"college"}]
在这种情况下,错误是由于对象被包含在数组中。
鉴于此,似乎问题是responseContent充满了无效的文字反斜杠(错误不只是显示转义的引号,因为它初看起来就会出现)。