alan.tham_1 Posted February 25, 2023 Share Posted February 25, 2023 Hi! I have a JSON datasource which is like this { "tpExt": [ { "organizationAddr": [ { "street": "8 High Street 08-01", "postcode": "648123" } ] } ]}[/code]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>[/code]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>[/code] 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 Link to comment Share on other sites More sharing options...
Solution Michael Bielkiewicz Posted February 26, 2023 Solution Share Posted February 26, 2023 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. Link to comment Share on other sites More sharing options...
alan.tham_1 Posted February 26, 2023 Author Share Posted February 26, 2023 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>[/code]And it displayed as expected. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now