我正在尝试反序列化此 Json 代码:
"hotkeyOptions": {
"autoSwitchHotkeyPreset": true,
"currentHotkeySetName": "Paladin",
"hotkeySets": {
"Newbie": {
"F10": {
"useObject": 5645,
"useType": "SelectUseTarget"
},
"F11": {
"useObject": 5456,
"useType": "SelectUseTarget"
},
"F12": {
"useObject": 7565,
"useType": "Use"
},
"F8": {
"useObject": 7547,
"useType": "UseOnYourself"
},
"F9": {
"useObject": 4214,
"useType": "SelectUseTarget"
}
},
"Mega Mage": {
"Ctrl+F1": {
"chatText": "heal friend",
"sendAutomatically": true
},
"Ctrl+F4": {
"chatText": "mega haste",
"sendAutomatically": true
},
"F1": {
"chatText": "haste",
"sendAutomatically": true
},
"F10": {
"useObject": 3412,
"useType": "SelectUseTarget"
},
"F11": {
"useObject": 5343,
"useType": "SelectUseTarget"
},
},
"Paladin": {
"F1": {
"useObject": 4643,
"useType": "UseOnYourself"
},
"F2": {
"useObject": 6433,
"useType": "UseOnYourself"
},
"F3": {
"chatText": "haste",
"sendAutomatically": true
},
"F5": {
"chatText": "heal",
"sendAutomatically": true
}
},
"Mage": {
"F1": {
"chatText": "explosion",
"sendAutomatically": true
},
"F12": {
"useObject": 3003,
"useType": "SelectUseTarget"
}
},
"Knight": {
"Ctrl+F1": {
"chatText": "poke go",
"sendAutomatically": true
},
"F1": {
"chatText": "haste",
"sendAutomatically": true
},
}
}
}
我在尝试读取它们的属性和值时遇到问题,但我无法获取“Newbie”、“Mega Mage”、“Paladin”等名称属性。
这就是我现在得到的:
JToken token = JObject.Parse(json);
JToken hotkeyConfig = token.SelectToken("hotkeyOptions");
JToken activeHotkey = hotkeyConfig.SelectToken("currentHotkeySetName");
this.ActiveHotkeySet = activeHotkey.Value<string>(); //This is working, returning the "Paladin" string
JToken hotkeysSet = hotkeyConfig.SelectToken("hotkeySets");
foreach (var set in hotkeysSet.Children()) {
foreach (JObject obj in set.Children<JObject>()) {
foreach(JProperty prop in obj.Properties()) {
var teste = prop.Name;
}
}
}
通过上面的代码,我可以使用“F10”、“Ctrl+F1”等键盘快捷键,但无法获取“家长姓名”(新手)。
有没有一种简单的方法来读取这种JSON结构?