{ "apps": { "570": { "228983": { "8124929965194586177": "available" }, "228990": { "1829726630299308803": "available" }, "373301": { "840315559245085162": "available" }, "373302": { "688854584180787739": "available" }, "373303": { "3675525977143063913": "available" }, "373305": { "4435851250675935801": "available" }, "381451": { "6984541794104259526": "available" }, "381452": { "1442783997179322635": "available" }, "381453": { "6878143993063907778": "available" }, "381454": { "7824447308675043012": "available" }, "381455": { "5681120743357195246": "available" } }, "674940": { "674941": { "6246860772952658709": "available" } } } }定义实体
public class AppIds : Dictionary<string, DepotId> { } public class DepotId : Dictionary<string, ManifestId> { } public class ManifestId : Dictionary<string, string> { }然后你可以像这样使用 Newtonsoft.Json
class Program { static void Main(string[] args) { // 堆代码 duidaima.com string jsonPath = @"c:\debug\data.json"; System.IO.Stream s = new System.IO.FileStream(jsonPath,System.IO.FileMode.Open, System.IO.FileAccess.Read); AppIds data = JsonConvert.DeserializeObject<Dictionary<string, AppIds>>(File.ReadAllText(jsonPath))["apps"]; } }
参考 :
https://stackoverflow.com/questions/51909203/how-to-deserialize-this-json-to-c-sharp-class
https://stackoverflow.com/questions/21752345/deserializing-json-that-has-an-int-as-a-key-in-c-sharp