I have a keyValupair of Hotel
details:
//This is where the data comes from : -
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
dynamic hotels1 = (dynamic)json_serializer.DeserializeObject(jso);
var keyValuePairs = hotels1["hotels"];
var hotelList = keyValuePairs["hotels"]; // hotelList[0] ={'key'='Code' ;value='123'}
//{'key'='Name'
// ;value='Sheraton'}
how do I convert this to a list of Hotel
List<Hotel> hotaals = new List<Hotel>();
where Hotel
is
public class Hotel {
public int code { get; set; }
public string name { get; set; }
}
I use a for loop to map fields, but my great boss says it's inefficient and I have to use Linq.
The loop I use
foreach (dynamic h in hotelList) {
oneHotel = new Hotel();
oneHotel.code = h["code"];
oneHotel.name = h["name"];
myHotels.Add(oneHotel);
}