【问题标题】:JSON to class conversion integer class name issue c#JSON到类转换整数类名问题c#
【发布时间】:2015-08-04 19:17:29
【问题描述】:

我收到这样的 JSON 响应。

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

当我尝试使用 .net 类进行映射时,它不允许我创建类似的类 公开课 1公开课 2。我想要这个 1 和 2 值作为排名,我也想要 href 和 url 值。那么如何通过创建类结构来实现呢?

提前致谢。

【问题讨论】:

标签: asp.net json c#-4.0 asp-classic


【解决方案1】:

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

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

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

【讨论】:

  • 非常感谢。它工作得很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多