【问题标题】:Nested Json Convert to Class C#嵌套的 Json 转换为 C 类#
【发布时间】:2019-01-28 23:51:34
【问题描述】:

我需要此 json 中对象 b 数组中的第一项。

{
   "error":[],
   "result":{
      "XXRPXXBT":{
         "a":[
            "0.000084280",
            "123",
            "123.000"
         ],
         "b":[
            "0.000084120",
            "24263",
            "24263.000"
         ],
         "c":[
            "0.000084140",
            "772.40225814"
         ],
         "v":[
            "1002684.00590349",
            "1081301.61838716"
         ],
         "p":[
            "0.000085783",
            "0.000085799"
         ],
         "t":[
            731,
            866
         ],
         "l":[
            "0.000083420",
            "0.000083420"
         ],
         "h":[
            "0.000086610",
            "0.000086720"
         ],
         "o":"0.000086300"
      }
   }
}

谁能告诉我类属性如何达到那个级别。我已经尝试使用字符串作为结果的 json 反序列化,但它在转换时失败。

我不必只拥有 b 数组中的第一项的所有值。

这就是我所做的:

TestResponse deserializedKrakenResult = JsonConvert.DeserializeObject<TestResponse>(json);

public class TestResponse 
    {
        public string[] result { get; set; }
    }

public class TestResponse 
    {
        public object[] result { get; set; }
    }

public class TestResponse 
    {
        public string result { get; set; }
    }

这些只是为了让它解析。

【问题讨论】:

  • 将此 JSON 粘贴到 json2csharp.com 并查看生成的类。从那里去....
  • @DavidG - 你对"I have tried a json decentralization with a string for result but it fails on the convert." 有什么不明白的地方?显然,它们偏离了标准,但那是因为它们(显然)对编码来说相对较新。无需迂腐。
  • @JᴀʏMᴇᴇ 嗯,你确定要标记我吗?
  • @DavidG - 绝对
  • @JᴀʏMᴇᴇ 那我怎么会迂腐呢?人们需要表现出一定程度的努力,这已纳入网站规则。

标签: c# json json.net


【解决方案1】:
  • 打开 Visual Studio
  • 打开编辑=>单击选择性粘贴=>单击Paste Json as Classes

结果如下:

public class Rootobject
{
    public object[] error { get; set; }
    public Result result { get; set; }
}

public class Result
{
    public XXRPXXBT XXRPXXBT { get; set; }
}

public class XXRPXXBT
{
    public string[] a { get; set; }
    public string[] b { get; set; }
    public string[] c { get; set; }
    public string[] v { get; set; }
    public string[] p { get; set; }
    public int[] t { get; set; }
    public string[] l { get; set; }
    public string[] h { get; set; }
    public string o { get; set; }
}

【讨论】:

  • 谢谢我不知道这个功能
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-09
  • 1970-01-01
  • 2018-01-07
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多