匹配JSON到C#class,坐标结构

Matching JSON to C# class, coordinates structure

由于 3 或 4 数组,我无法将 json 格式转换为 c# 对象。这是我似乎无法翻译的相关 json 部分。

{
    "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
            [
                [
                    [151165.781300000846386, 202858.609400000423193],
                    [151187.015600003302097, 202873.359400000423193],
                    [151188.046899996697903, 202874.078099999576807],
                    [151220.828100003302097, 202896.875],
                    [151191.5625, 203005.656300000846386],
                    [151223.546899996697903, 203030.593800000846386],
                    [151226.468800000846386, 203029.5],
                    [151249.453100003302097, 203047.015599999576807],
                    [151281.421899996697903, 203009.296900000423193]
                ]
            ]
        ]
    }
}

我用下面的代码试了一下:

public class geometry
{
    public string type { get; set; }

    public List<List<double[]>> coordinates { get; set; }
}

public class geometry
{
    public string type { get; set; }

    public List<List<string[]>> coordinates { get; set; }
}

public class geometry
{
    public string type { get; set; }

    public double[][] coordinates { get; set; }
}

public class geometry
{
    public string type { get; set; }

    public string[][] coordinates { get; set; }
}

public class geometry
{
    public string type { get; set; }

    public List<coordinates> coordinates { get; set; }
}
public class coordinates 
{
    List<string> subcoordinates` { get; set; }
}

老实说,我不知道他们为什么这样组织。对我来说似乎没有必要,或者因为它们是坐标而以这种方式实现是有原因的吗?

您的 Json 结构表示多层嵌套坐标数组 - 每次您看到方括号 ([...]) 中包含的内容时,它就是一个数组。

您的 coordinates 属性 包含一个 4 级嵌套数组 - 因此它可以反序列化到此 c# class:

public class Geometry
{
    [JsonProperty("type")]
    public string Type { get; set; }

    [JsonProperty("coordinates")]
    public List<List<List<List<double>>>> Coordinates { get; set; }
}