Hi! I have a JSON datasource which is like this
{ "tpExt": [ { "organizationAddr": [ { "street": "8 High Street 08-01", "postcode": "648123" } ] } ] }
I have a field which is like this:
<field name="street" class="java.lang.String"> <property name="net.sf.jasperreports.json.field.expression" value="tpExt.organizationAddr.street"/> <fieldDescription><![CDATA[tpExt.organizationAddr.street]]></fieldDescription> </field>
And my textfield is
<textField isBlankWhenNull="true"> <reportElement x="110" y="114" width="430" height="17"/> <textElement lineSpacing="Single"/> <textFieldExpression><![CDATA[$F{street}]]></textFieldExpression> </textField>
But I am getting the display with square brackets and quotes
["8 High Street 08-01"]
How to remove the square brackets and quotes? Thanks
2 Answers:
Posted on February 25, 2023 at 10:32pm
I believe that in this case, the square brackets are indicating an array of values. So you are outputing an array (with just a single value in the array). If you treat it as an array in your TextField reference, you should be able to get individual elements. If you only expect one address ever, you can simply get the first element of the array and I think it will display as you desire.
Posted on February 26, 2023 at 4:09am
Thanks! I changed my field to :
<field name="street" class="java.lang.String"> <property name="net.sf.jasperreports.json.field.expression" value="tpExt.organizationAddr[0].street"/> <fieldDescription><![CDATA[tpExt.organizationAddr.street]]></fieldDescription> </field>
And it displayed as expected.