我错误地认为location属性没有被反序列化?
来自pollinglocation.googleapis.com
的JSON片段...
"locations":[[{"dataset_id":841,
"election_id":2,
"id":"841:100001351",
"address":{"location_name":"ROBERT S PAYNE SCHOOL",
"line1":"1201 Floyd St",
"city":"Lynchburg",
"state":"VA",
"zip":"245011913"},
"directions":"",
"polling_hours":"6 AM - 7 PM"}]],
...
Java对象
public class PollingLocation {
public PollingLocation() {
}
String status;
ArrayList<ArrayList<Anonymous>> locations;
public class Anonymous {
public Anonymous() {
}
String dataset_id;
String election_id;
String id;
Address address;
}
public class Address {
public Address() {
}
String location_name;
String line1;
String city;
String stage;
String zip;
String polling_hours;
}
}
反序列化的代码
PollingLocation obj2 = gson.fromJson(json, PollingLocation.class);
答案 0 :(得分:0)
一切。 具体来说,您不能使用内部类或集合类。
public class PollingLocation {
public PollingLocation() {
}
String status;
Anonymous[][] locations;
}
class Anonymous {
public Anonymous() {
}
String dataset_id;
String election_id;
String id;
Address address;
}
class Address {
public Address() {
}
String location_name;
String line1;
String city;
String stage;
String zip;
String polling_hours;
}