Vishwajeet Vishwajeet - 2 years ago 125
JSON Question

Convert json into class object in c#

Hi i have the following json response,how i convert it into a c# class object

{ "err_code": "0", "org": "CGK", "des": "SIN", "flight_date": "20120719",

] }

Answer Source

Use JavaScriptSerializer to convert it to a class.

string jsonInput="have your valid json input here"; //
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
Customer objCustomer  = jsonSerializer.Deserialize<Customer >(jsonInput)

Assuming you want to convert it to a Customer classe's instance. Your class should looks similar to the JSON structure (Properties)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download