How to deserialize JSON into a dynamic object in C# without creating classes?
Hello everyone! I'm new to C# and working with JSON data from an external API. The problem is that the JSON structure keeps changing, and I have to create new classes for deserialization every time. This is very inconvenient, especially when I need to quickly test the server response.
Here's an example of the JSON I receive:
```json
{
"name": "John Doe",
"age": 30,
"address": {
"city": "New York",
"zip": "10001"
},
"hobbies": ["reading", "gaming"]
}
```
Currently I'm doing it like this:
```csharp
public class Person {
public string Name { get; set; }
public int Age { get; set; }
public Address Address { get; set; }
public List Hobbies { get; set; }
}
public class Address {
public string City { get; set; }
public string Zip { get; set; }
}
No answers yet.
Log in to leave an answer
Blogs