我正在使用C#和Json.NET.如果我有一个JObject,我想要一个对象内的键列表,类似于object.Keys()返回对象中的键的方式.这似乎很明显,但我很难找到一种方法来做到这一点.
编辑: 我正在遍历对象,我想在我经历时吐出对象中的所有键.我意识到这个例子会导致多次看到相同的密钥,这对我的需求是可以的.
public void SomeMethod(JObject parent) {
foreach (JObject child in parent.Children()) {
if (child.HasValues) {
//
// Code to get the keys here
//
SomeMethod(child);
}
}
}
Run Code Online (Sandbox Code Playgroud)