Deserializing JSON result with Json & JavaScriptSerializer

后端 未结 2 719
遥遥无期
遥遥无期 2021-01-16 02:45

here\'s my problem:

I\'m trying to deserialize json that hasn\'t been done by me. The format of the json is as follows:

{\"responseId\":1200,
\"avail         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 03:17

    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 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.

提交回复
热议问题