Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用JSONPath在字符串数组中查找值?_C#_Json.net_Jsonpath - Fatal编程技术网

C# 如何使用JSONPath在字符串数组中查找值?

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

我正在尝试筛选一个Form段落对象列表,其中hasContent属性为true,legalStatutes字符串数组包含一个带“AIA”的字符串。问题是“AIA”在数组中并不总是处于零位置

$.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是不起作用的。我找到答案后会把它贴出来吗