【发布时间】:2018-09-08 20:21:30
【问题描述】:
我有一个 Json 文件,对象序列化正确,但问题是 json 有一个看起来像字典的东西,键是字符串“0”、“1”等等。
有什么方法可以在不涉及编写自己的解析器的情况下将它们正确反序列化为列表?
"WeaponSlots":{
"0":{
"WeaponInstalled":null,
"AllowedWeaponTypes":{
"0":{
"0":2
}
},
"AllowedWeapons":null
},
"1":{
"WeaponInstalled":null,
"AllowedWeaponTypes":{
"0":{
"0":2
}
},
"AllowedWeapons":null
}
【问题讨论】:
-
试试JSON.NET。
-
这个 JSON 是什么创建的?你能修复它以使 WeaponSlots 成为正确的列表吗?
-
您可以使用 app.quicktype.io/#l=cs 生成一组匹配的 C# 类,然后使用 Json.NET 将其解析为这些类型。