JSON 值无法转换为 System.Collections.Generic.List

Pri*_*JKB 9 c# json generic-list

我正在尝试列出游戏中的所有项目,using System.Text.Json; 我对使用 .json 文件非常陌生,我尝试这样做来测试它是否有效:

            List<Item> AllItems = new List<Item>();
            string json = File.ReadAllText("Items.json");
            AllItems = Deserialize<List<Item>>(json);
            WriteLine(AllItems[0].Name);
Run Code Online (Sandbox Code Playgroud)

它不允许我将其转换为列表这是 json 文件

{
  "Item": [
    {
      "Weapon": [
        {
          "CritChance": 60,
          "HitChance": 80,
          "OGDamge": 15,
          "Damage": 15,
          "Damage_Type": "Physical",
          "Weapon_Type": "Fist",
          "Player": null,
          "APUsage": 4,
          "ID": 1,
          "Name": "Debug",
          "Value": 16,
          "Rarity": "Common",
          "Item_Type": "Weapon"
        },
        {
          "CritChance": 40,
          "HitChance": 70,
          "OGDamge": 15,
          "Damage": 15,
          "Damage_Type": "Electric",
          "Weapon_Type": "Bow",
          "Player": null,
          "APUsage": 5,
          "ID": 2,
          "Name": "Debug2",
          "Value": 15,
          "Rarity": "Common",
          "Item_Type": "Weapon"
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

谁能帮我吗 :)

小智 16

您的 json 文件以大括号开头,这意味着您需要包含名为 Item 的 Item 列表的父类,或者您只需更改您的 json 文件,以 [ 括号开头,这意味着您的主要对象是集合。