如何获取所有子 json 的父键名,其参数的键名为“$oid”?

How to get the parent key name of all sub json which has a parameter with key name "$oid"?

{
"id":{"$oid":5c9238241ea62ed5d516fcae},
"createdOn" : ISODate("2019-03-19T03:50:00.000Z"),
"version" : "1.0",
"ruleMasterID":{"$oid":5c90df381ea62ed5d5138266},
}

我有一个这样的json。我想要“$oid”所在的键名作为子 json 中的键。 因此,在此 json 中,id 和 ruleMasterID 是预期的输出。 谁能告诉我如何在 C# 中编写代码来获得相同的代码?

如果你不想递归搜索,那么你可以简单地做一个 LINQ 语句:

JObject jsonObject = JObject.Parse(json);
var keys = (from x in jsonObject.Children() where x.Children().Any(y => (y as JObject)?.ContainsKey("$oid")==true) select x.Path).ToList();