亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

反序列化Json字典以列出

反序列化Json字典以列出

C#
陪伴而非守候 2022-01-09 15:08:13
我有一個 Json 文件,對象序列化正確,但問題是 json 看起來像一個字典,鍵是字符串“0”、“1”等等。有沒有什么方法可以在不涉及編寫自己的解析器的情況下將它們正確反序列化為列表?"WeaponSlots":{        "0":{           "WeaponInstalled":null,           "AllowedWeaponTypes":{              "0":{                 "0":2              }           },           "AllowedWeapons":null        },        "1":{           "WeaponInstalled":null,           "AllowedWeaponTypes":{              "0":{                 "0":2              }           },           "AllowedWeapons":null        }示例文件:https : //pastebin.com/i3LQ3L7j
查看完整描述

2 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

您可以使用數據類型Dictionary<string, object>來反序列化這個..


查看完整回答
反對 回復 2022-01-09
?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

static void Main(string[] args)

{

    // load the file.

    var file = File.ReadAllText("Example.json");


    // to generate the 'Example' classes from JSON I used

    // https://app.quicktype.io and changed the name to 'Example'

    var example = JsonConvert.DeserializeObject<Example>(file);


    // select the value of each dictionary entry into a list.

    var sections = example.Sections.Select(x => x.Value).ToList();

}


查看完整回答
反對 回復 2022-01-09
  • 2 回答
  • 0 關注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號