我需要对以下 json 数据设置什么连接表达式?



我在Jaspersoft Studio中生成了一个报告,并使用了一个Dataadapter,它是一个JSON Rest Service。

对于简单值,一切正常,但现在我的 json 结构中有一个数组:

{
...
"A": {
"B": [
{
"C": "asdf"
},
{
"C": "xyz"
}
]
},
... }

在我的报告中,我想创建一个表并列出其中 C 的所有值。创建表和数据集后,我的报表如下所示:

<subDataset name="Dataset" uuid="e3a0dc52-fba1-48fe-a067-84fae6a3448c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Adapter"/>
<queryString language="json">
<![CDATA[A.B]]>
</queryString>
<field name="C" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="C"/>
<fieldDescription><![CDATA[C]]></fieldDescription>
</field>
</subDataset>
...
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Dataset" uuid="d44a71a8-7a49-440a-abbe-056276894f5c">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression></dataSourceExpression>
</datasetRun>
<jr:column width="200" uuid="22888b9f-4eff-483e-8d7c-d0d6748e8ce7">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:columnHeader style="Table_CH" height="30"/>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="b7df3878-ef55-4a7b-b89b-4083da2d5297"/>
<textFieldExpression><![CDATA[$F{C}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>

但是当我单击预览时,我的表中从未获得任何数据?

我很确定我的连接表达式有问题,但我在文档中找不到任何线索,正确的表达式是什么。

连接表达式需要

((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("A.B") 

因此,subDataSource的参数必须是 JSON 结构中数组的路径。

最新更新