Gson を使用してこの JSON を解析しようとしています。
{
"status": "status",
"lang": "lang",
"guid": "guid",
"name": "name",
"tags": "tags",
"address": "address",
"description": "description",
"size": "M",
"url": "http:\/\/",
"email": "mymail@mysite.com",
"fax": "",
"tel": "000 000 00 00",
"total_votes": "0",
"total_value": "0",
"rate": 5,
"open2424": "0",
"category_main_name": "category_main_name",
"category_name": "category_name",
"category_main_name2": "category_main_name2",
"category_name2": "category_name2",
"category_main_name3": "category_main_name3",
"category_name3": "category_name3",
"park_type": "park_type",
"park_handicap": "0",
"park_free": "1",
"park_description": "",
"datemodinfo": "2012-12-15 18:18:05",
"sponsor": "2",
"sponsorstart": "2012-12-16 13:38:51",
"sponsorend": "2013-12-16 13:38:51",
"zip": "zip",
"town": "town",
"area": "area",
"latitude": "latitude",
"longitude": "longitude",
"distance_info": {
"distance": 10,
"unit": "unit"
},
"image": "image",
"url": "url",
"open": "1",
"openinghours": [{
"schedules": {
"day0": {
"periods": [{
"from": "09:00",
"to": "12:30"
},
{
"from": "14:00",
"to": "18:00"
}],
"date": "2013-08-12"
},
"day1": {
"periods": [{
"from": "09:00",
"to": "12:30"
},
{
"from": "14:00",
"to": "18:00"
}],
"date": "2013-08-13"
},
"day2": {
"periods": [{
"from": "09:00",
"to": "12:30"
},
{
"from": "14:00",
"to": "18:00"
}],
"date": "2013-08-14"
},
"day3": {
"periods": [{
"from": "09:00",
"to": "12:30"
},
{
"from": "14:00",
"to": "18:00"
}],
"date": "2013-08-15"
},
"day4": {
"periods": [{
"from": "09:00",
"to": "12:30"
},
{
"from": "14:00",
"to": "18:00"
}],
"date": "2013-08-16"
},
"day5": {
"date": "2013-08-17"
},
"day6": {
"date": "2013-08-18"
}
},
"title": "title"
}]
}
次のコードで JSON を解析します。
Gson gson = new Gson();
new GsonBuilder().serializeNulls().create();
Reader reader = new InputStreamReader(source);
response = gson.fromJson(reader, ResponseShow.class);
これは私のResponseShow
クラスです:
public class ResponseShow {
@SerializedName("status")
public String status;
@SerializedName("lang")
public String lang;
@SerializedName("guid")
public String guid;
@SerializedName("name")
public String name;
@SerializedName("tags")
public String tags;
@SerializedName("address")
public String address;
@SerializedName("description")
public String description;
@SerializedName("size")
public String size;
@SerializedName("url")
public String url;
@SerializedName("email")
public String email;
@SerializedName("fax")
public String fax;
@SerializedName("tel")
public String tel;
@SerializedName("total_votes")
public String total_votes;
@SerializedName("total_values")
public String total_values;
@SerializedName("rate")
public String rate;
@SerializedName("open2424")
public String open2424;
@SerializedName("category_main_name")
public String category_main_name;
@SerializedName("category_name")
public String category_name;
@SerializedName("category_main_name2")
public String category_main_name2;
@SerializedName("category_name2")
public String category_name2;
@SerializedName("category_main_name3")
public String category_main_name3;
@SerializedName("category_name3")
public String category_name3;
@SerializedName("park_type")
public String park_type;
@SerializedName("park_handicap")
public String park_handicap;
@SerializedName("park_free")
public String park_free;
@SerializedName("park_description")
public String park_description;
@SerializedName("datemodinfo")
public String datemodinfo;
@SerializedName("sponsor")
public String sponsor;
@SerializedName("sponsorstart")
public String sponsorstart;
@SerializedName("sponsorend")
public String sponsorend;
@SerializedName("town")
public String town;
@SerializedName("area")
public String area;
@SerializedName("latitude")
public String latitude;
@SerializedName("longitude")
public String longitude;
@SerializedName("distance_info")
public Map<String, String> distance_info = new HashMap<String, String>();
@SerializedName("zip")
public String zip;
@SerializedName("image")
public String image;
@SerializedName("ligoo_url")
public String ligoo_url;
@SerializedName("open")
public int open;
public List<openinghours> openinghours;
@SerializedName("query")
public String query;
}
これは私のopeninghours
クラスです:
public class openinghours {
public List<schedules> schedules;
@SerializedName("title")
public String title;
}
これは私のSchedules
クラスです:
public class schedules {
public List<day0> day0;
public List<day1> day1;
public List<day2> day2;
public List<day3> day3;
public List<day4> day4;
public List<day5> day5;
public List<day6> day6;
}
そして私のday0
クラス:
public class day0 {
@SerializedName("date")
public String date;
public List<periods> periods;
}
問題は、解析しようとしているときに次のエラーが発生することday0
です。
Error: java.lang.IllegalStateException: Expected BEGIN_ARRAY goal was BEGIN_OBJECT at line 1 column 2414