I am trying to generate classes from json to deseralize to c# object but list object is not correct, where am i going wrong? Available rooms should be a list as per my assumption but It does not work.
Below is my JSON
{
"avaliabilitiesResponse": {
"Hotels": {
"Hotel": [
{
"HotelCode": "0017855",
"HotelsName": "Hilton Jeddah",
"Location": "Jeddah, Saudi Arabia",
"Rating": "4",
"LowestPrice": "35",
"Currency": "EUR",
"IsReady": "true",
"AvailableRooms": {
"AvailableRoom": [
{
"RoomCode": "11245",
"RoomName": "Standard",
"Occupancy": "1",
"Status": "true"
},
{
"RoomCode": "12000",
"RoomName": "Double",
"Occupancy": "2",
"Status": "true"
},
{
"RoomCode": "99685",
"RoomName": "Twin",
"Occupancy": "2",
"Status": "true"
}
]
}
},
{
"HotelCode": "0018799",
"HotelsName": "Ramada Continental Jeddah",
"Location": "Jeddah, Saudi Arabia",
"Rating": "3",
"LowestPrice": "345",
"Currency": "USD",
"IsReady": "false",
"AvailableRooms": {
"AvailableRoom": [
{
"RoomCode": "00012",
"RoomName": "Triple Standard",
"Occupancy": "3",
"Status": "false"
},
{
"RoomCode": "5477",
"RoomName": "Triple Sea View",
"Occupancy": "3",
"Status": "false"
},
{
"RoomCode": "996666",
"RoomName": "Standard Double",
"Occupancy": "2",
"Status": "true"
}
]
}
},
{
"HotelCode": "0010888",
"HotelsName": "Qasr Al Sharq",
"Location": "Jeddah, Saudi Arabia",
"Rating": "5",
"LowestPrice": "3500",
"Currency": "SAR",
"IsReady": "true",
"AvailableRooms": {
"AvailableRoom": {
"RoomCode": "102432",
"RoomName": "Suite",
"Occupancy": "4",
"Price": "3500",
"Status": "true"
}
}
}
]
}
}
}
it gets converted to c# like this.
public class AvailableRooms
{
public object AvailableRoom { get; set; } //this is not correct i assume, i tried to fix it like Hotels have Hotel in Json to have a list here but it does not work.
}
public class Hotel
{
public string HotelCode { get; set; }
public string HotelsName { get; set; }
public string Location { get; set; }
public string Rating { get; set; }
public string LowestPrice { get; set; }
public string Currency { get; set; }
public string IsReady { get; set; }
public AvailableRooms AvailableRooms { get; set; }
}
public class Hotels
{
public List<Hotel> Hotel { get; set; }
}
public class AvaliabilitiesResponse
{
public Hotels Hotels { get; set; }
}
public class RootObject
{
public AvaliabilitiesResponse avaliabilitiesResponse { get; set; }
}
I have tried using Json2csharp as well as visual studio's paste special option for class conversion, I still don't get available rooms in my object.