简体   繁体   English

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

[英]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},
}

i have a json like this.我有一个这样的json。 i want the key name where "$oid" exists as key in sub json.我想要“$oid”作为子json中的键存在的键名。 so, in this json id and ruleMasterID are the expecting output.所以,在这个 json id 和 ruleMasterID 中是预期的输出。 can anyone tell me that how to write code to get the same in C#?谁能告诉我如何编写代码以在 C# 中获得相同的代码?

If you don't want a recursive search, then you could simply do a LINQ statement:如果你不想递归搜索,那么你可以简单地做一个 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM