我如何使用Jsonpath表达式通过以下json字符串实现所需的输出。在列表中选择departmentlabel加标题(如果left为null或为空,请选择空列表,然后根据空合并条件生成列表)
JsonString
{
"Library": [
{
"DepartmentLabel": "",
"Books": [
{
"Title": "ABC"
},
{
"Title": "DEF"
},
{
"Title": "GHi"
}
]
},
{
"DepartmentLabel": "XYZ",
"Books": []
}
]
}
所需的输出
[ “ ABC”, “ DEF”, “ GHi”, “ XYZ” ]
使用Json表达式
string JsonPath ="{$.Library[*].DepartmentLabel}?{$.Library[*].Books[*].Title}";
IEnumerable<JToken> elementsTokens = jObject.SelectTokens(jsonPath);