在JRXML中使用JSONQL将Json数组作为逗号分隔的值 [英] Json array as comma separated values using JSONQL in JRXML

查看:38
本文介绍了在JRXML中使用JSONQL将Json数组作为逗号分隔的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已将json输入json作为

We have input json to jrxml as

{
  "ID": "5c2c7662f256a1452b0ed8b2",
  "MarketData": {
        "markets": [ { "id": "1001", "name": "val1" }, { "id": "1002", "name": "Val2" }, { "id": "1003", "name": "val3" } ],
        "products": [
        {"id": "1001", "proname": "shoe"},
        {"id": "1002", "name": "bag"},
        {"id": "1003", "name": "cap"}
        ],
        "location":"ABC"
    }
}

我们有json,其中包含市场,产品的价值列表.

We have json that contains list of values of markets, products .

我们需要将此json中的值显示为 位置:ABC 市场:val1,Val2,val3 售出产品:鞋,包,帽

We need to show values from this json as Location : ABC Markets : val1,Val2,val3 Products Sold: shoes,bag,cap

使用此处提供的解决方案,我可以将市场显示为逗号分隔的值

Using this solution provided here i am able to display Markets as comma separated values Jasper converting list of values of json to comma separated values using jsonQL

如果我使用子数据集并显示,则输出为 位置:ABC 市场:val1 val1,val2 val1,val2,val3 产品:鞋子 鞋,包 鞋子,袋子,帽子

Same technique if i use subdataset and display i get output as Location : ABC Markets : val1 val1,val2 val1,val2,val3 Products : shoes shoes,bag shoes,bag,cap

我将主数据集声明为

<queryString language="jsonql">
        <![CDATA[]]>
    </queryString>
    <field name="location" class="java.lang.String">
        <property name="net.sf.jasperreports.jsonql.field.expression" value="location"/>
        <fieldDescription><![CDATA[location]]></fieldDescription>
    </field>

然后将子数据集设置为市场

then subdataset as markets as

<subDataset name="marketList" uuid="01e76955-f29e-4d52-991b-aa0149bfdb37">
        <field name="name" class="java.lang.String">
            <property name="net.sf.jasperreports.jsonql.field.expression" value="name"/>
        </field>
        <variable name="allname" class="java.lang.String">
            <variableExpression><![CDATA[$V{allname} != null ? $V{allname} + ", " + $F{name} : $F{name}]]></variableExpression>
        </variable>
</subDataset>

在jrxml中将这些字段引用为

referenced these fields in jrxml as

<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                            <datasetRun subDataset="marketList" uuid="565f0c3a-76b6-4527-b0d2-d306c5f4e20c">
                                <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("$.MarketData.markets")]]></dataSourceExpression>
                            </datasetRun>
                            <jr:listContents height="16" width="103">
                                <textField>
                                    <reportElement x="0" y="0" width="100" height="16" uuid="7f2eaa2a-20b5-4598-bbf1-758f61dc3fc8"/>
                                    <textFieldExpression><![CDATA[$V{allname}]]></textFieldExpression>
                                </textField>
                            </jr:listContents>
                        </jr:list>

这将输出显示为

Markets : val1
          val1,val2
          val1,val2,val3

但是预期输出是

Location : ABC
Markets : val1,val2,val3
Products :shoes,bag,cap

如何将具有值列表的子数据集显示为逗号分隔的值.

How to show subdataset that has list of values as comma separated values .

谢谢 Anjana

推荐答案

在列表的textField中,您可以将评估时间设置为PageReport之类,并仅在第一条记录中显示它,如下所示:

In your list's textField you could set the evaluation time to something like Page or Report and display it only for the first record, something like so:

<jr:listContents height="0" width="180">
    <frame>
        <reportElement x="0" y="0" width="100" height="0" uuid="3c9872d0-ef6c-4643-9cf9-e78bc6996d3e">
            <property name="ShowOutOfBoundContent" value="true"/>
            <printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
        </reportElement>
        <textField evaluationTime="Report">
            <reportElement x="0" y="0" width="100" height="16" uuid="f5a23577-4e57-4542-81a4-06ed679be920"/>
            <textFieldExpression><![CDATA[$V{allname}]]></textFieldExpression>
        </textField>
    </frame>
</jr:listContents>

将textField包裹在一个高度为0的框架中,以避免在列表内部产生不必要的空白.

The textField is wrapped in a 0 height frame to avoid unnecessary white space generation inside the list.

这篇关于在JRXML中使用JSONQL将Json数组作为逗号分隔的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆