Here is the json string.
I would like to generate c# classes from it. But there is a problem when I tried via http://json2csharp.com/.
Because room_types has names but not type. How can I solve this issue?
{
"api_version" : 5,
"lang" : "en_US",
"hotels" :
[
{
"ta_id" : 258705 ,
"partner_id" : "hc",
"name" : "Hotel Commonwealth",
"street" : "500 Commonwealth Avenue",
"city" : "Boston",
"postal_code" : "02215",
"state" : "Massachusetts",
"country" : "USA",
"latitude" : 42.348808,
"longitude" : -71.094971,
"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"],
"url" : "http://www.partner-site.com/hotelcommonwealth",
"email" : "[email protected]",
"phone" : "555-555-5555",
"fax" : "555-555-5555",
"room_types" :
{
"Fenway Room" :
{
"url" : "http://www.partner-site.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.partner-site.com/hotel_commonwealth/commonwealth_room",
"desc" : "One king bed with pillowtop mattress, Frette Italian linens, down bedding, multiple pillows. View of Commonwealth Avenue."
}
}
}
]
}
And here is the classes which I generated via http://json2csharp.com/
public class FenwayRoom
{
public string url { get; set; }
public string desc { get; set; }
}
public class CommonwealthRoom
{
public string url { get; set; }
public string desc { get; set; }
}
public class RoomTypes
{
public FenwayRoom __invalid_name__Fenway Room { get; set; }
public CommonwealthRoom __invalid_name__Commonwealth Room { get; set; }
}
public class Hotel
{
public int ta_id { get; set; }
public string partner_id { get; set; }
public string name { get; set; }
public string street { get; set; }
public string city { get; set; }
public string postal_code { get; set; }
public string state { get; set; }
public string country { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
public string desc { get; set; }
public List<string> amenities { get; set; }
public string url { get; set; }
public string email { get; set; }
public string phone { get; set; }
public string fax { get; set; }
public RoomTypes room_types { get; set; }
}
public class RootObject
{
public int api_version { get; set; }
public string lang { get; set; }
public List<Hotel> hotels { get; set; }
}
I see that something is wrong in room_types. How should I create room types class? I am confused at this point. what should be the type of "Fenway room" and "commonwealth room" ?
EDIT But but my real problem is that "if I have a 3rd room type, Do I need to create a class for it?" I am developing c# web api according to given json format. I have many different room types. such as : standart room, family room, deluxe room etc. how can I prepare my web api code according to given room type format? shal I create a class for every room type? as fenway room, coomonwealt room. Shouldn't it be a genereic class for rooms?