我有以下 json 搅拌
{
"api_version" : 2 ,
"lang" : "en_US",
"hotels" :
[
{
"hotel_id" : 258705 ,
"desc" : "The Hotel Commonwealth stands above the Kenmore Square \"T\" subway station in Boston, Mass. Fenway Park is located two blocks away, while the shops along Newbury Street are three blocks from the hotel.",
"amenities" : ["RESTAURANT","NON_SMOKING"],
"room_types" :
{
"Fenway Room" :
{
"url" : "http://www.partnersite.com/hotel_commonwealth/fenway_room",
"desc" : "One king bed with pillowtop mattress, Frette Italian linens, down bedding, multiple pillows. View of Fenway Park."
},
"Commonwealth Room" :
{
"url" : "http://www.partnersite.com/hotel_commonwealth/commonwealth_room",
"desc" : "One king bed with pillowtop mattress, Frette Italian linens, down bedding, multiple pillows. View of Commonwealth Avenue."
}
}
}
]
}
我创建了以下 poco 类。我可以使用 NewtonSoft 反序列化上述字符串。
internal class FenwayRoom
{
}
internal class CommonwealthRoom
{
}
internal class RoomTypes
{
[JsonProperty("Fenway Room")]
public FenwayRoom FenwayRoom { get; set; }
[JsonProperty("Commonwealth Room")]
public CommonwealthRoom CommonwealthRoom { get; set; }
}
internal class Hotel
{
}
}
现在的问题是,对于每个房间类型,我都必须创建一个分隔类。有没有更好的方法呢?