Jump to content
JasperReports Library 7.0 is now available ×

Textfield from JSON source has square brackets and quotes


alan.tham_1
Go to solution Solved by Michael Bielkiewicz,

Recommended Posts

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

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...