json 数组中的嵌套项未被反序列化

Nested item in json array is not being deserialized

我正在尝试从 api.

反序列化 json 字符串

除嵌套项目外的所有作品 - 始终以空结尾的位置

这是字符串结构:

[
    {
        "CompanyProfile": "<p>A&amp;B Inc etc...</p>",
        "Address": "56 Test Street, Test, UK",
        "Location": {
            "Latitude": 61.52787,
            "Longitude": -4.32095,
            "Zoom": 13,
            "Icon": null,
            "Format": 0,
            "Api": null,
            "SearchTyped": null
        },
        "Id": 1723,
        "Name": "A&B Inc"
    },
        {
        "CompanyProfile": "<p>B&amp;C Inc etc...</p>",
        "Address": "57 Test Street, Test, UK",
        "Location": {
            "Latitude": 61.2122,
            "Longitude": -4.31111,
            "Zoom": 13,
            "Icon": null,
            "Format": 0,
            "Api": null,
            "SearchTyped": null
        },
        "Id": 1723,
        "Name": "B&C Inc"
    },
]

这些 类 映射到:

public class MemberDto
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public string? CompanyProfile { get; set; }
    public string? Address { get; set; }
    public Location? Location { get; internal set; }
}

public class Location
{
    public decimal Latitude { get; set; }
    public decimal Longitude { get; set; }
}

这是反序列化代码:

var result = await response.Content.ReadAsStringAsync();
var members = JsonConvert.DeserializeObject<List<MemberDto>>(result);

我知道我也可以使用 ReadFromJsonAsync<List<MemberDto>>(),但使用 ReadFromString 这样我就可以在反序列化之前检查 json。无论如何,ReadFromJsonAsync 的结果完全相同。

除 Location 之外的所有内容都已成功反序列化

有人知道问题出在哪里吗?

删除 Location setter 中的内部访问修饰符。

public Location? Location { get; set; }