为了账号安全,请及时绑定邮箱和手机立即绑定

使用键将嵌套的 JObject 反序列化为 List

使用键将嵌套的 JObject 反序列化为 List

C#
函数式编程 2021-06-04 10:37:28
我需要使用 Newtonsoft.Json 将 json 反序列化回对象实例。但是,它是一个列表类型对象,条目的键对我很有用。我不知道如何在不手动一一映射字段的情况下自动反序列化。这是回应:{    coins: {        365Coin: {            id: 74,            tag: "365",            algorithm: "Keccak",            lagging: true,            listed: false,            status: "No available stats",            testing: false        },        Aiden: {            id: 65,            tag: "ADN",            algorithm: "Scrypt-OG",            lagging: true,            listed: false,            status: "No available stats",            testing: false        },        Adzcoin: {            id: 157,            tag: "ADZ",            algorithm: "X11",            lagging: false,            listed: false,            status: "Active",            testing: false        }        ... [With various key representing the name of coins]    }}完整回复:https : //whattomine.com/calculators.json我对这门课的最佳猜测是:internal class WhatToMineCalculatorsResponse{    // Should be Dictionary???    [JsonProperty("coins")]    public IList<WhatToMineCalculatorResponse> Coins { get; set; }}internal class WhatToMineCalculatorResponse{    // I want the key set in this field    public string Name { get; set; }    [JsonProperty("id")]    public int Id { get; set; }    [JsonProperty("tag")]    public string Symbol { get; set; }    [JsonProperty("status")]    public string Status { get; set; }    [JsonProperty("algorithm")]    public string Algo { get; set; }    [JsonProperty("listed")]    public bool IsListed { get; set; }}请注意,我希望将键包含在我的类中,但不希望作为字典的键。以后很难找回密钥。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 531 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信