我需要使用 Newtonsoft.Json 將 json 反序列化回對象實例。但是,它是一個列表類型對象,條目的鍵對我很有用。我不知道如何在不手動一一映射字段的情況下自動反序列化。這是回應(yīng):{ 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] }}完整回復(fù):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; }}請注意,我希望將鍵包含在我的類中,但不希望作為字典的鍵。以后很難找回密鑰。
使用鍵將嵌套的 JObject 反序列化為 List
函數(shù)式編程
2021-06-04 10:37:28