gpt4 book ai didi

json - 使用 ireport 在 Json 数据源中带点的字段名称

转载 作者:行者123 更新时间:2023-12-04 21:12:54 25 4
gpt4 key购买 nike

我的示例 json 文件内容

{
"FlightLog":{
"FlightLog.crewMembers":[

],
"destinationStationCode":"JPN",
"FlightLog.destinationStationCode":"IND",
"FlightLog.originStationCode":"IND",
"FlightLog._lockVersion":"0",
"FlightLog.flightNum":"123"
}
}

我想获取 FlightLog.FlightLog.originStationCode 的值。

例如:
当我如下声明字段名称时,我得到值“JPN”
<field name="FlightLog.destinationStationCode" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog.destinationStationCode]]></fieldDescription>
</field>

而如果我声明如下字段,
<field name="destinationStationCode" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog.FlightLog.destinationStationCode]]></fieldDescription>
</field>

我没有得到上述代码的任何值(value)。

我尝试使用
<field name="destinationStationCode" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog[FlightLog.destinationStationCode]]]></fieldDescription>
</field>
<field name="destinationStationCode2" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog.FlightLog\\.destinationStationCode]]></fieldDescription>
</field>

我怎样才能做到这一点?
UPDATE

我的 jrxml 是,
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="062e3e2d-b648-49c7-b4a5-1d3c4fbdfc6b">
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="FlightLog" class="java.lang.Object">
<fieldDescription><![CDATA[FlightLog]]></fieldDescription>
</field>
<detail>
<band height="20" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="555" height="20" uuid="dc09b2c4-31b1-4458-8097-2e912e80b3a2"/>
<textFieldExpression><![CDATA[$F{FlightLog}.get("FlightLog.destinationStationCode")]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

更新 2

我无法将数据传递给子报表,例如:我有一个如下所示的 json,
"MaintLogResource":{
"MaintLogResource._lockVersion":"0",
"MaintLogResource.resource":[
{
"TEST" : "TEST1",
"ResourceType.resourceTimeHours":3.0,
"ResourceType.resourceDescription":"resourceDescription",
"ResourceType.resourceCount":2,
"ResourceType.resourceIdentifier":{
"ResourceIdentifier.resourceIdentifier":"resourceIdentifier",
"ResourceIdentifier.typeOfResourceIdentifier":"EQUIPMENT"
}
}
]
}

我如何将其传递给子报告,

我试过如下,
((net.sf.jasperreports.engine.data.JsonDataSource)((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("MaintLogResource")).subDataSource("MaintLogResource.resource") 

但是上面的代码给了我错误,
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
Source text : ((net.sf.jasperreports.engine.data.JsonDataSource)((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("MaintLogResource")).subDataSource("MaintLogResource")
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:203)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:966)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:392)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:294)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:455)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2044)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:778)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:288)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:126)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:300)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:757)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:1003)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: net.sf.jasperreports.engine.JRException: No node available. Iterate or rewind the data source.
at net.sf.jasperreports.engine.data.JsonDataSource.subDataSource(JsonDataSource.java:445)
at net.sf.jasperreports.engine.data.JsonDataSource$subDataSource$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Logbook_1434518442194_713295.evaluate(calculator_Logbook_1434518442194_713295:311)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)
... 19 more

如何将数据传递给子报表?

更新3

我可以将数据传递给子报告,如下所示,
new net.sf.jasperreports.engine.data.JsonDataSource(new ByteArrayInputStream($F{MaintLogResource}.get("MaintLogResource.resource").toString().getBytes()), "")

当我读取带有“.”的键时我无法获得该值,而如果没有点的键我能够读取该值,例如:我能够获得“TEST”键的值(value),但不能为其他人获得值(value)。

最佳答案

destinationStationCodeFlightLog 中的 key 因此它可以直接访问。相同的规则应用于其他键,直到任何键都有句号,如 FlightLog.destinationStationCode ,因为句点有它自己的含义(对象上的访问属性)。因此它没有给出任何值(您可以通过用任何其他字符替换句点来验证,例如“_”,然后一切正常)。

要访问此属性,建议您创建一个字段 FlightLog类型 Object , 喜欢

<field name="FlightLog" class="java.lang.Object">
<fieldDescription><![CDATA[FlightLog]]></fieldDescription>
</field>

并访问其属性,如
<textField>
<reportElement x="0" y="0" width="555" height="29" uuid="afa65308-c0ae-4375-b8e5-99af4b69e02e"/>
<textFieldExpression><![CDATA[$F{FlightLog}.destinationStationCode]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="29" width="555" height="29" uuid="2009cbd3-7fb7-4d9e-8067-b03937aefcaa"/>
<textFieldExpression><![CDATA[$F{FlightLog}.get("FlightLog.destinationStationCode")]]></textFieldExpression>
</textField>

希望这可以帮助。

我的文件 -

JSON
{
"FlightLog":{
"FlightLog.crewMembers":[

],
"destinationStationCode":"JPN",
"FlightLog.destinationStationCode":"IND",
"FlightLog.originStationCode":"IND",
"FlightLog._lockVersion":"0",
"FlightLog.flightNum":"123"
}
}

jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="53cc1a16-1ec1-486c-82f6-51915fa4b069">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="FlightLog" class="java.lang.Object">
<fieldDescription><![CDATA[FlightLog]]></fieldDescription>
</field>
<detail>
<band height="58" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="29" uuid="afa65308-c0ae-4375-b8e5-99af4b69e02e"/>
<textFieldExpression><![CDATA[$F{FlightLog}.destinationStationCode]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="29" width="555" height="29" uuid="2009cbd3-7fb7-4d9e-8067-b03937aefcaa"/>
<textFieldExpression><![CDATA[$F{FlightLog}.get("FlightLog.destinationStationCode")]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

关于json - 使用 ireport 在 Json 数据源中带点的字段名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30703286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com