Json.net中JObject.SelectTokens中的Json路径查询未返回结果 [英] Json path query in JObject.SelectTokens in Json.net not returning results
问题描述
我有一个像这样的json
I have a json like this
{
"Attributes": [
{
"Name": "attr1",
"Value": "abcd"
},
{
"Name": "attr2",
"Value": "abcde"
},
{
"Name": "attr3",
"Value": "abcdef"
}
],
"SomeObject": {
"Attributes": [
{
"Name": "attr1",
"Value": "xyz"
},
{
"Name": "attr2",
"Value": "xyza"
},
{
"Name": "attr3",
"Value": "wxyxz"
}
]
}
}
我正在实现一个通用代码.每当对象结构可能更改时,但是属性结构将保持不变.我想通过匹配它们的名称来查找所有属性,例如Name =="attr1".我读了有关JsonPath的文章.我正在使用Json.net(Newtonsoft)库进行JSON操作.我来这很杂技-> JObject.SelectTokens(jsonPath)
.我创建了一个$.[?(@.Name=='attr1')]
JSON路径查询,并在 http://jsonpath.com/进行了测试.它工作正常,但是在C#代码中却给了我空结果.谁能给我建议一个解决方案,您的帮助已到位!
I am implementing a common code. Every time the object structure may change, But the attributes structure is going to remain same. I want find all the attributes by matching their name like Name=="attr1". I read about JsonPath. I am using Json.net(Newtonsoft) library for json manipulation. I came acros this -> JObject.SelectTokens(jsonPath)
. I created one json path query as $.[?(@.Name=='attr1')]
and tested at http://jsonpath.com/ . It is working properly but in c# code it is giving me null results. Can anyone please suggest me a solution, your help is appreaciated!
推荐答案
使用此JsonPath只是在$
Use this JsonPath just putting an extra dot after $
$..[?(@.Name=='attr1')]
这篇关于Json.net中JObject.SelectTokens中的Json路径查询未返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!