Newtonsoft.Json的 JsonConvert可以传两层json的字符串吗?
假设我们有以下嵌套的 JSON 字符串:
- {
- "Name": "John",
- "Age": 30,
- "Address": {
- "Street": "123 Main St",
- "City": "Anytown",
- "ZipCode": "12345"
- }
- }
复制代码 定义对应的 C# 类首先,我们需要定义与 JSON 结构相对应的 C# 类: - public class Address
- {
- public string Street { get; set; }
- public string City { get; set; }
- public string ZipCode { get; set; }
- }
- public class Person
- {
- public string Name { get; set; }
- public int Age { get; set; }
- public Address Address { get; set; }
- }
复制代码
|