Deserializing JSON result with Json & JavaScriptSerializer

一个人想着一个人 提交于 2019-12-01 13:36:27

It's difficult to interpret the structure of your objects based on your description but I was able to deserialize your sample JSON using the following minimal code:

var result = JsonConvert.DeserializeObject<getAvailableHotelResponse>(json);

public class getAvailableHotelResponse
{
    public int responseId;
    public availableHotel[] availableHotels;
    public int totalFound;
    public string searchId;
}

public class availableHotel
{
    public string processId;
    public string hotelCode;
    public string availabilityStatus;
}

Neither of the above listed Objects fully match the JSON schema... Are you sure whoever serialized the object to JSON used any of those classes you're trying to deserialize to? If not, just create a class that you deserialize the JSON to:

public class HotelSearchResponse
{
    public int responseID {get;set;}
    public hotel[] availableHotels {get;set;}
    public int totalFound {get;set;}
    public string searchId {get;set;}
}

If the hotel array doesn't work, try List<hotel> instead for availableHotels type.

P.S. The closest object to the JSON from the ones listed in your question is getAvailableHotelResponse but it declares availableHotels as single hotel instace, instead the JSON has an array of hotel objects returned.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!