Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to iterate this json and convert it to C# object but problem is standard_room and executive_room are dynamic it can be anything other room type also so cannot create any classes at design time.


JavaScript
{  
   "room_types":{  
      "Standard_Room":{  
         "price":13136.200000,
         "fees":0,
         "fees_at_checkout":0,
         "taxes":0,
         "taxes_at_checkout":0,
         "final_price":13136.200000,
         "currency":"INR",
         "num_rooms":1
      },
      "Executive_Room":{  
         "price":10771.684000,
         "fees":0,
         "fees_at_checkout":0,
         "taxes":0,
         "taxes_at_checkout":0,
         "final_price":10771.684000,
         "currency":"INR",
         "num_rooms":1
      }
   }
}
Posted

Try fastJSON.JSON.ToDynamic() : fastJSON[^]
 
Share this answer
 
you can do here like,

if you want to convert this JSON then,

Example,

Class Rooms
{With some properties}

Rooms[] obj=null;
JavaScriptSerializer ser = new JavaScriptSerializer();
obj = ser.Deserialize(JsonString, typeof(Rooms[])) as Rooms[];

if want this to be list then,

List<rooms> room=obj.toList<rooms>();

let us know how it goes.

Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900