如何修复 "invalid expression, current token ... not ended properly" 错误?
How to fix "invalid expression, current token ... not ended properly" error?
这是我的数据
{
"errorCode": null,
"errorMessage": null,
"responseItems": [
{
"personFirstName": "t16239d",
"personLastName": "submitter 1",
"hireDate": "20161106",
"terminationDate": null,
"startMonthYear": "01_2017",
"endMonthYear": "12_2017",
"staffTimeOffAllowances": [
{
"officeCode": null,
"startMonthYear": null,
"endMonthYear": null,
"personId": null,
"personCode": null,
"allowancesIntotal": 10,
"allowancesUsed": 0,
"allowancesSubmitted": 0,
"allowancesApproved": 0,
"allowancesRemaining": 10,
"timeOffType": {
"id": 1284,
"continent": "EU",
"alphaId": "CA",
"code": "SUM1",
"description": "summer friday1",
"account": "ADMIN1",
"colourCode": "#CCCCCC",
"visibility": "R",
"approvalRequired": true,
"commentRequired": false,
"paid": true
},
"timeOffTypeWithoutAllowance": false,
"proRataAllowanceData": false
},
{
"officeCode": null,
"startMonthYear": null,
"endMonthYear": null,
"personId": null,
"personCode": null,
"allowancesIntotal": 0,
"allowancesUsed": 3,
"allowancesSubmitted": 0,
"allowancesApproved": 0,
"allowancesRemaining": 3,
"timeOffType": {
"id": 1342,
"continent": "EU",
"alphaId": "CA",
"code": "SICK",
"description": "Sickness",
"account": "SICK",
"colourCode": "#CCCCCC",
"visibility": "R",
"approvalRequired": true,
"commentRequired": false,
"paid": true
},
"timeOffTypeWithoutAllowance": true,
"proRataAllowanceData": false
}
]
}
]
}
我正在尝试提取具有 timeOffTypeWithoutAllowance = true
.
的第一个 staffTimeOffAllowances
条目的 allowancesUsed
字段的值
Mu 当前尝试是:
staffTimeOffAllowances[?(@.timeOffTypeWithoutAllowance==true)].allowancesUsed[0]
它编译得很好,但是当我尝试预览它时,它失败了
invalid expression, current token staffTimeOffAlowances[?(@ not ended properly
我尝试了同一个表情的很多变体,但没有任何乐趣。有人可以告诉我我错过了什么吗?
基本json
查询语言需要绝对表达式。我建议将您的查询停止在您想要的 JSON 属性 之上一级,以便您可以将其用作字段表达式(使用 "leaf" 值需要一个特殊的字段表达式 - "."
- 并可能产生不可预知的结果)。话虽如此,您应该对这个查询和字段映射没问题:
<queryString language="json">
<![CDATA[responseItems.staffTimeOffAllowances(timeOffTypeWithoutAllowance == true)[0]]]>
</queryString>
<field name="allowancesUsed" class="java.lang.Integer"/>
从 JasperReports 6.3.1 开始,您可以使用更多 flexible/advanced jsonql
语言。只需将上面的 queryString 声明替换为:
这个:
<queryString language="jsonql">
<![CDATA[..staffTimeOffAllowances.*(timeOffTypeWithoutAllowance == true)[0]]]>
</queryString>
此查询转换为:"get the staffTimeOffAllowances
property from anywhere, get its children that have timeOffTypeWithoutAllowance
, select the first one"
或者这个:
<queryString language="jsonql">
<![CDATA[..timeOffTypeWithoutAllowance(@val == true)^[0]]]>
</queryString>
此查询转换为:"get the timeOffTypeWithoutAllowance
property with a true value from anywhere, get its parents, select the first one"
重要说明:json
和 jsonql
是与 JsonPath 无关的自定义查询语言,尽管它们有一些相似之处。 json
是第一个(也是非常简单的)尝试提供一种查询 JSON 结构的方法,然后是 jsonql
,它旨在取代 json
,因为它提供了更多的功能和更可预测。
这是我的数据
{
"errorCode": null,
"errorMessage": null,
"responseItems": [
{
"personFirstName": "t16239d",
"personLastName": "submitter 1",
"hireDate": "20161106",
"terminationDate": null,
"startMonthYear": "01_2017",
"endMonthYear": "12_2017",
"staffTimeOffAllowances": [
{
"officeCode": null,
"startMonthYear": null,
"endMonthYear": null,
"personId": null,
"personCode": null,
"allowancesIntotal": 10,
"allowancesUsed": 0,
"allowancesSubmitted": 0,
"allowancesApproved": 0,
"allowancesRemaining": 10,
"timeOffType": {
"id": 1284,
"continent": "EU",
"alphaId": "CA",
"code": "SUM1",
"description": "summer friday1",
"account": "ADMIN1",
"colourCode": "#CCCCCC",
"visibility": "R",
"approvalRequired": true,
"commentRequired": false,
"paid": true
},
"timeOffTypeWithoutAllowance": false,
"proRataAllowanceData": false
},
{
"officeCode": null,
"startMonthYear": null,
"endMonthYear": null,
"personId": null,
"personCode": null,
"allowancesIntotal": 0,
"allowancesUsed": 3,
"allowancesSubmitted": 0,
"allowancesApproved": 0,
"allowancesRemaining": 3,
"timeOffType": {
"id": 1342,
"continent": "EU",
"alphaId": "CA",
"code": "SICK",
"description": "Sickness",
"account": "SICK",
"colourCode": "#CCCCCC",
"visibility": "R",
"approvalRequired": true,
"commentRequired": false,
"paid": true
},
"timeOffTypeWithoutAllowance": true,
"proRataAllowanceData": false
}
]
}
]
}
我正在尝试提取具有 timeOffTypeWithoutAllowance = true
.
staffTimeOffAllowances
条目的 allowancesUsed
字段的值
Mu 当前尝试是:
staffTimeOffAllowances[?(@.timeOffTypeWithoutAllowance==true)].allowancesUsed[0]
它编译得很好,但是当我尝试预览它时,它失败了
invalid expression, current token staffTimeOffAlowances[?(@ not ended properly
我尝试了同一个表情的很多变体,但没有任何乐趣。有人可以告诉我我错过了什么吗?
基本json
查询语言需要绝对表达式。我建议将您的查询停止在您想要的 JSON 属性 之上一级,以便您可以将其用作字段表达式(使用 "leaf" 值需要一个特殊的字段表达式 - "."
- 并可能产生不可预知的结果)。话虽如此,您应该对这个查询和字段映射没问题:
<queryString language="json">
<![CDATA[responseItems.staffTimeOffAllowances(timeOffTypeWithoutAllowance == true)[0]]]>
</queryString>
<field name="allowancesUsed" class="java.lang.Integer"/>
从 JasperReports 6.3.1 开始,您可以使用更多 flexible/advanced jsonql
语言。只需将上面的 queryString 声明替换为:
这个:
<queryString language="jsonql"> <![CDATA[..staffTimeOffAllowances.*(timeOffTypeWithoutAllowance == true)[0]]]> </queryString>
此查询转换为:"get the
staffTimeOffAllowances
property from anywhere, get its children that havetimeOffTypeWithoutAllowance
, select the first one"或者这个:
<queryString language="jsonql"> <![CDATA[..timeOffTypeWithoutAllowance(@val == true)^[0]]]> </queryString>
此查询转换为:"get the
timeOffTypeWithoutAllowance
property with a true value from anywhere, get its parents, select the first one"
重要说明:json
和 jsonql
是与 JsonPath 无关的自定义查询语言,尽管它们有一些相似之处。 json
是第一个(也是非常简单的)尝试提供一种查询 JSON 结构的方法,然后是 jsonql
,它旨在取代 json
,因为它提供了更多的功能和更可预测。