2
我有兩個目的一個是儀表盤和第二的房間,我有一個JSON是這個樣子無法反序列化對象的實例出來的START_ARRAY令牌
{
"hotel_id":"1",
"hotel_room":"200",
"hotel_properties":[{
"id":"1",
"room_type":"Single",
"rack_rate":"2000",
"publish_rate":"1800",
"discount":"10",
"availiable":"40",
"total":"50"
},
{
"id":"2",
"room_type":"Double",
"rack_rate":"4000",
"publish_rate":"3600",
"discount":"10",
"availiable":"45",
"total":"50"
}
]
}
和對象是
public class DashBoard {
private int hotel_id;
private int hotel_room;
@JsonProperty("hotel_properties")
private Room hotel_properties;
}
還有另一種對象間是這個樣子
public class Room {
private Long id;
private String room_type;
private String rack_rate;
private String publish_rate;
private String discount;
private String availiable;
private String total;
}
我隱藏所有構造函數,setter和getter FO [R#1,但它是在我的代碼 我想解析JSON使用此代碼
JsonReader jsonReader = new JsonReader();
ObjectMapper mapper = new ObjectMapper();
try {
JSONObject json = jsonReader.readJsonFromUrl("http://localhost/quinchy/json/dashboard.json");
DashBoard dsh = mapper.readValue(json.toString(), DashBoard.class);
System.out.println(json.toString());
} catch (IOException | JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
使用ObjectMapper從URL到對象,但我得到這個錯誤
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of Object out of START_ARRAY token
請幫我從這個
使用'名單'而不是Room'的''中的類DashBoard'感謝 –
Vaseph