我正在使用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);
}
}
}