C# 如何使用JSONPath在字符串数组中查找值?
我正在尝试筛选一个Form段落对象列表,其中hasContent属性为true,legalStatutes字符串数组包含一个带“AIA”的字符串。问题是“AIA”在数组中并不总是处于零位置C# 如何使用JSONPath在字符串数组中查找值?,c#,json.net,jsonpath,C#,Json.net,Jsonpath,我正在尝试筛选一个Form段落对象列表,其中hasContent属性为true,legalStatutes字符串数组包含一个带“AIA”的字符串。问题是“AIA”在数组中并不总是处于零位置 $.businessResponse.formParagraphList[?((@.hasContent==true) && (@.legalStatutes.indexOf('AIA') > -1))] 只有当“AIA”是数组中的第一项时,下面的JSONPath才有效 $.bu
$.businessResponse.formParagraphList[?((@.hasContent==true) && (@.legalStatutes.indexOf('AIA') > -1))]
只有当“AIA”是数组中的第一项时,下面的JSONPath才有效
$.businessResponse.formParagraphList[ ? ((@.hasContent == true) && (@.legalStatutes[0] == 'AIA'))] {
"rbacUser": null,
"businessResponse": {
"formParagraphList": [{
"id": 1261,
"hasContent": true,
"legalStatutes": [
"Pre_AIA",
"AIA"
]
},
{
"id": 67,
"hasContent": true,
"legalStatutes": [
"AIA",
"Pre_AIA"
]
},
{
"id": 68,
"hasContent": true,
"legalStatutes": [
"Pre_AIA"
]
}
]
}
}
有没有一种方法可以在不知道JSON对象索引的情况下使用JSONPath检查JSON对象中字符串数组中是否存在特定字符串?好的,找到了解决问题的方法。使用
.indexOf()
方法检查数组中是否存在该字符串
$.businessResponse.formParagraphList[?((@.hasContent==true) && (@.legalStatutes.indexOf('AIA') > -1))]
更新:
上述JSONPath在在线评估器中有效,但在Newtonsoft for C#中不起作用。这是我和这个图书馆合作的成果
$.businessResponse.formParagraphList[?(@.hasExaminerNote==true && @.legalStatutes[*]=='Pre_AIA')]
需要注意的是,在c#中使用newtonsoft是不起作用的。我找到答案后会把它贴出来吗