Deserialize JSON Text into C# Objects
Deserializing JSON text into C# objects can be accomplished through a few simple steps.
For the provided JSON response:
{ "err_code": "0", "org": "CGK", "des": "SIN", "flight_date": "20120719", "schedule": [ ["W2-888", "20120719", "20120719", "1200", "1600", "03h00m", "737-200", "0", [["K", "9"], ["F", "9"], ["L", "9"], ["M", "9"], ["N", "9"], ["P", "9"], ["C", "9"], ["O", "9"]]], ["W2-999", "20120719", "20120719", "1800", "2000", "01h00m", "MD-83", "0", [["K", "9"], ["L", "9"], ["M", "9"], ["N", "9"]]] ] }
Rootobject r = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(jsonString);
Replace "jsonString" with the variable containing the JSON text. Rename "Rootobject" with a more descriptive class name.
string errCode = r.err_code; string org = r.org;
Follow these steps to effortlessly convert JSON text into C# objects, enabling you to work with structured data in your applications.
The above is the detailed content of How to Deserialize JSON Text into C# Objects?. For more information, please follow other related articles on the PHP Chinese website!