Home > Backend Development > C++ > How Can I Deserialize JSON into C# Dynamic Objects?

How Can I Deserialize JSON into C# Dynamic Objects?

Mary-Kate Olsen
Release: 2025-02-03 01:41:09
Original
548 people have browsed it

How Can I Deserialize JSON into C# Dynamic Objects?

Serially sequence of JSON to C#dynamic object

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.

Solution using json.net

JSON.NET provides a way to easily achieve dynamic JSON degradation:

Solution using newtonsoft.json.linq

dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");

string name = stuff.Name;
string address = stuff.Address.City;
Copy after login

Similarly, newtonsoft.json.linq also provides another option:

<多> More resources

dynamic stuff = JObject.Parse("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");

string name = stuff.Name;
string address = stuff.Address.City;
Copy after login
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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template