Android 改装POJO为空,但JSON有效
这件事让我抓狂。JSON响应是有效的:Android 改装POJO为空,但JSON有效,android,json,pojo,retrofit,Android,Json,Pojo,Retrofit,这件事让我抓狂。JSON响应是有效的: { "MRData": { "xmlns": "http://ergast.com/mrd/1.4", "series": "f1", "url": "http://ergast.com/api/f1/current/2.json", "limit": "30", "offset": "0", "total": "1", "RaceTab
{
"MRData": {
"xmlns": "http://ergast.com/mrd/1.4",
"series": "f1",
"url": "http://ergast.com/api/f1/current/2.json",
"limit": "30",
"offset": "0",
"total": "1",
"RaceTable": {
"season": "2014",
"round": "2",
"Races": [
{
"season": "2014",
"round": "2",
"url": "https://en.wikipedia.org/wiki/2014_Malaysian_Grand_Prix",
"raceName": "Malaysian Grand Prix",
"Circuit": {
"circuitId": "sepang",
"url": "http://en.wikipedia.org/wiki/Sepang_International_Circuit",
"circuitName": "Sepang International Circuit",
"Location": {
"lat": "2.76083",
"long": "101.738",
"locality": "Kuala Lumpur",
"country": "Malaysia"
}
},
"date": "2014-03-30",
"time": "08:00:00Z"
}
]
}
}
}
响应的POJO:
public class ApiResponse {
MRData mrdata;
public class MRData {
String xmlns;
String series;
String url;
String limit;
String offset;
String total;
RaceTable raceTable;
}
}
apiResponse对象始终为空。任何人都可以在这里指出POJO对象的错误所在?
谢谢。我在这里看到了几个潜在问题:
公共类ApiResponse{MRData MRData;}
如果您希望POJO的变量与JSON返回的变量不同,您应该使用
@SerlizedName
我们在使用Gson
反序列化JSON时遇到问题,发现区分大小写是罪魁祸首,因为我们可以在另一个类中使用类,这同样有效。@Emmanuel-您提出的第一点无效。我已经使用了相当长的一段时间,这种模式是非常普遍的。外壳是我的问题。!ThanksIt与其说是在表明自己的观点,不如说是在说“这可能会造成问题”。我从未见过这样做。很高兴你的问题解决了。