Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting JSON to C# classes in ASP.Net MVC
    primarykey
    data
    text
    <p>I'm trying to write an API - the expected output (for a 3rd party) as shown on their website is the JSON below:</p> <pre><code>{ "api_version" : 4 , "hotel_ids" : [97497], "hotels" : [ { "hotel_id": 97497, "room_types": { "Fenway Room": { "url": "someurlhere", "price": 178.50, "room_code": "SINGLE" } } } ] } </code></pre> <p>I'm using the online tool: <a href="http://json2csharp.com/" rel="nofollow">http://json2csharp.com/</a></p> <p>It gives me the following classes:</p> <pre><code>public class FenwayRoom { public string url { get; set; } public double price { get; set; } public string room_code { 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&lt;int&gt; hotel_ids { get; set; } public List&lt;Hotel&gt; hotels { get; set; } } </code></pre> <p>You can see in RoomTypes:</p> <p><code>FenwayRoom __invalid_name__Fenway Room { get; set; }</code></p> <p>I'm wondering if their spec for the JSON is wrong, or is there a way for me to create the classes to return the JSON they are expecting?</p> <p>In the example, I believe the room type "Fenway Room" is a variable - so I don't think it can also be a class name. But it may just be that I don't know how to create a class like this.</p> <p>I just can't figure out the "Fenway Room" - which I think needs to have something like: "Room Name":"Fenway Room" - but maybe there is another way of defining the classes so that it doesn't need a label "Room Name".</p> <p>I'd appreciate any help in confirming if it is possible to create classes to match against their JSON.</p> <p>Thanks, Mark</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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