【问题标题】:How can i declare list in a Json object?如何在 Json 对象中声明列表?
【发布时间】:2016-11-10 00:51:45
【问题描述】:

我有一个 json 对象声明,我想在其中使用 DateTime 列表。我该如何申报?我在当前定义中遇到错误。

public class TurtleTrade
{        
    [JsonProperty("Powerbars")]
    public int  Powerbars { get; set; }
    [JsonProperty("PowerbarsTime")]
    public List<DateTime>()  PowerbarsTime { get; set; } // Error here
}

【问题讨论】:

  • 删除括号。
  • 我在当前定义中遇到错误 - 你遇到了什么错误?
  • 公开列表 PowerbarsTime { get;放; }

标签: c# .net json list json.net


【解决方案1】:

正如您所说,问题/错误不是因为[JsonProperty("PowerbarsTime")] 您可以在其下定义列表。真正的问题是List&lt;T&gt; 的声明语法。 List&lt;DateTime&gt;() 不是 DateTime 列表的有效声明,它必须是 List&lt;DateTime&gt; 所以 public List&lt;DateTime&gt;() PowerbarsTime { get; set; } 应该是这样的:

public List<DateTime> PowerbarsTime { get; set; }

【讨论】:

    猜你喜欢
    • 2020-04-26
    • 2021-08-30
    • 2017-01-18
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2016-12-22
    相关资源
    最近更新 更多