Home >Backend Development >C++ >How Can I Deserialize JSON into C# Dynamic Objects?
This article discusses the dissection of JSON data into a C#dynamic type, so as to avoid creating a large number of classes to use DataContractJSONSERIALIZER.
JSON.NET provides a way to easily achieve dynamic JSON degradation:
<code class="language-csharp">dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }"); string name = stuff.Name; string address = stuff.Address.City;</code>
Similarly, newtonsoft.json.linq also provides another option:
More resources
<code class="language-csharp">dynamic stuff = JObject.Parse("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }"); string name = stuff.Name; string address = stuff.Address.City;</code>If you need to learn more, please refer to the part of the official document on "Use Dynamic Query JSON" part: [Link to Document]
The above is the detailed content of How Can I Deserialize JSON into C# Dynamic Objects?. For more information, please follow other related articles on the PHP Chinese website!