I need to create clasess from json, but found some strange part that really troubles me. This is example from documentation that i have to response to them. There is some "Fenway Room" that should be variable but it looks it is value (room name) that contain other properties.
{
"api_version" : 4 ,
"hotel_ids" : [97497],
"num_hotels" : 1,
"hotels" :
[
{
"hotel_id": 97497,
"room_types":
{
"Fenway Room":
{
"url": "",
"price": 178,
"fees": 80,
"fees_at_checkout": 0,
"taxes": 20,
"taxes_at_checkout": 0,
"final_price": 278
}
}
}
]
}
here are classes online generated, and looks wrong. it looks that is not possible.
public class FenwayRoom
{
public string url { get; set; }
public int price { get; set; }
public int fees { get; set; }
public int fees_at_checkout { get; set; }
public int taxes { get; set; }
public int taxes_at_checkout { get; set; }
public int final_price { get; set; }
}
public class RoomTypes
{
public FenwayRoom __invalid_name__Fenway Room { get; set; }
}
public class Hotel
{
public int hotel_id { get; set; }
public RoomTypes room_types { get; set; }
}
public class RootObject
{
public int api_version { get; set; }
public List<int> hotel_ids { get; set; }
public int num_hotels { get; set; }
public List<Hotel> hotels { get; set; }
}
This is my first working with json, so im really confused. Json looks valid, but it is possible to create classes from that or i should create response manualy?... joining strings...
added example:
"hotels" :[
{
"hotel_id" : 258705 ,
"room_types" :
{
"Room 1" :
{
"url" :"", "price" : 1136 , "fees" : 101.55 , "taxes" : 50.00 , "final_price" : 1287.55 ,
}
"Room 2" :
{
"url" :"", "price" : 1136 , "fees" : 101.55 , "taxes" : 50.00 , "final_price" : 1287.55 ,
}
}
}
]
Where "Room 1" and "Room 2" are room titles, not properties or variables... it can be anything here.