У меня есть вложенный объект JSON какУплотненного JSON объект синтаксического анализа с использованием GSON
{
"hours": {
"Friday": {
"close": "21:00",
"open": "11:00"
},
"Tuesday": {
"close": "21:00",
"open": "11:00"
}
},
"open": true,
"categories": [
"Fast Food",
"Restaurants"
],
"city": "Dravosburg",
"review_count": 7,
"name": "Mr Hoagie",
"neighborhoods": [
],
"longitude": -79.9007057,
"state": "PA",
"stars": 3.5,
"latitude": 40.3543266,
"attributes": {
"Take-out": true,
"Drive-Thru": false,
"Good For": {
"dessert": false,
"latenight": false
},
"Caters": false,
"Noise Level": "average",
"Takes Reservations": false,
"Delivery": false,
"Ambience": {
"romantic": false,
"intimate": false,
"classy": false
},
"Parking": {
"garage": false,
"street": false
},
"Has TV": false,
"Outdoor Seating": false,
"Attire": "casual"
},
"type": "business"
}
Я использую GSON разобрать этот объект JSON. Я создал классы POJO, как показано ниже:
public class BusinessPojo {
private String type;
private String name;
private ArrayList<String> neighborhoods = new ArrayList<>();
private ArrayList<String> categories = new ArrayList<>();
private BusinessDay hours = new BusinessDay();
private String city;
private boolean open;
private String state;
private double latitude;
private double longitude;
private float stars;
private int review_count;
private BusinessAttributes attributes;
//getters and setters
}
public class BusinessDay {
private BusinessHourTime monday = new BusinessHourTime();
private BusinessHourTime tueday = new BusinessHourTime();
private BusinessHourTime wednesday = new BusinessHourTime();
private BusinessHourTime thursday = new BusinessHourTime();
private BusinessHourTime friday = new BusinessHourTime();
private BusinessHourTime satday = new BusinessHourTime();
private BusinessHourTime sunday = new BusinessHourTime();
// getters and setters
}
public class BusinessHourTime {
private String open;
private String close;
//getters and setters
}
и аналогично для Attributes
, внутри атрибутов для Parking
, Ambience
и GoodFor
. Это мой код:
String line = "json object"
Gson g = new Gson();
BusinessPojo businessJsonObj = g.fromJson(line, BusinessPojo.class);
Когда я пытаюсь получить доступ к "Drive-Thru"
как
System.out.println(businessJsonObj.getAttributes().isDriveThru());
я получаю значение false
, однако, когда я пытаюсь получить доступ open
из Friday
или Tuesday
я null
как
System.out.println(businessJsonObj.getHours().getTuesday().getOpen());
Может ли кто-нибудь помочь мне понять, какую ошибку я совершил в своем коде?