Home >Backend Development >C++ >How to Deserialize JSON into Dynamic Objects in C#?
C# allows the adaptation of JSON content into a dynamic object without creating a class for data binding.
JSON.NET provides a simple way to sequence JSON's derivatives into dynamic objects:
<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>
newtonsoft.json.linq also allows dynamic JSON back serialization:
Query dynamic json
<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>Dynamic objects allow the JSON attribute to query JSON attributes like the C# attribute of this machine:
More information
For details about querying dynamic JSON in C#, see:
<code class="language-csharp">string city = stuff.Address.City;</code>
Document: Use dynamic query json
The above is the detailed content of How to Deserialize JSON into Dynamic Objects in C#?. For more information, please follow other related articles on the PHP Chinese website!