Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserializing JSON result with Json & JavaScriptSerializer
    text
    copied!<p>here's my problem:</p> <p>I'm trying to deserialize json that hasn't been done by me. The format of the json is as follows:</p> <pre><code>{"responseId":1200, "availableHotels":[ {"processId":"HA-84665605","hotelCode":"UKKTLT","availabilityStatus":"InstantConfirmation",...}, {"processId":"HA-28600965","hotelCode":"UKKTLT","availabilityStatus":"InstantConfirmation",...}, {"processId":"HI-63991185","hotelCode":"UKJOVF","availabilityStatus":"InstantConfirmation",...} ], "totalFound":9, "searchId":"TP-84026455"} </code></pre> <p>And the following classes:</p> <ul> <li>getAvailableHotelResponse w/properties: <ul> <li>hotelObj availableHotels</li> <li>int totalFound</li> <li>String responseId</li> <li>String searchId</li> </ul></li> <li>hotelObj w/properties: <ul> <li>hotel hotel</li> </ul></li> <li>hotel w/properties: <ul> <li>processId</li> <li>hotelCode</li> <li>availabilityStatus</li> <li>...</li> </ul></li> </ul> <p>Therefore, what I know I can tell from looking at the json is that it contains information of a getAvailableHotelResponse object.</p> <p>So, I tried the following using <code>JsonConvert</code> and <code>JavaScriptSerializer</code>:</p> <pre><code>JavaScriptSerializer ser = new JavaScriptSerializer(); getAvailableHotelResponse availableResponse = ser.Deserialize&lt;getAvailableHotelResponse&gt;(json); // Exception: "Type 'com.hotelspro.api.getAvailableHotelResponse' is not supported for deserialization of an array" List&lt;getAvailableHotelResponse&gt; items = ser.Deserialize&lt;List&lt;getAvailableHotelResponse&gt;&gt;(json); // items.Count = 0 List&lt;getAvailableHotelResponse&gt; result = JsonConvert.DeserializeObject&lt;List&lt;getAvailableHotelResponse&gt;&gt;(json); // Exception: "Cannot deserialize JSON object into type 'System.Collections.Generic.List`1[com.hotelspro.api.getAvailableHotelResponse]'." getAvailableHotelResponse result2 = JsonConvert.DeserializeObject&lt;getAvailableHotelResponse&gt;(json); // Exception: Cannot deserialize JSON array into type 'com.hotelspro.api.hotelObj'. </code></pre> <p>What's the correct sentence in order to deserialize this object?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload