JSON 到 class 转换整数 class 名称问题 c#

JSON to class conversion integer class name issue c#

我收到了 JSON 这样的回复。

{
"serp":
    {
        "1":
        {
            "href": "href1.com",
            "url": "url1.com"
        },
        "2":
        {
            "href": "href2.com",
            "url": "url2.com"
        }
     }
  }

当我尝试使用 .net class 进行映射时,它不允许我创建 class 之类的 public class 1public class 2。我想要这个 1 和 2 值作为等级,我也想要 href 和 url 值。那么如何通过创建 class 结构来获得它呢?

提前致谢。

This answer 演示了一个可能适用于使用字典对象的问题的解决方案。你可以像这样创建一个 class(只是一个例子):

public class ExampleObject
{
    public string href { get; set; }
    public string url { get; set; }
}

并使用字典中的那些对象作为值,而键是 Integer 类型。这将允许按键排序并访问存储在 urlhref.

中的信息