c# - Convert json string to CLR Types -
i have following json stirng
{ "api_version" : 2 , "lang" : "en_us", "hotels" : [ { "hotel_id" : 258705 , "desc" : "the hotel commonwealth stands above kenmore square \"t\" subway station in boston, mass. fenway park located 2 blocks away, while shops along newbury street 3 blocks hotel.", "amenities" : ["restaurant","non_smoking"], "room_types" : { "fenway room" : { "url" : "http://www.partnersite.com/hotel_commonwealth/fenway_room", "desc" : "one king bed 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 pillowtop mattress, frette italian linens, down bedding, multiple pillows. view of commonwealth avenue." } } } ] }
and have created following poco classes.i able deserialize above string using 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 { } }
now problem every roomtype have create septate class.is there better approach this?
the properties per room appear same, need introduce single room
class e.g.
public class room { [jsonproperty("url")] public string url { get; set; } [jsonproperty("desc")] public string description { get; set; } } public class roomtypes { [jsonproperty("fenway room")] public room fenwayroom { get; set; } [jsonproperty("commonwealth room")] public room commonwealthroom { get; set; } }
Comments
Post a Comment