iReport 使用json 数据源

前面几番折腾,已经安装好了iReport并且可以正常启动,这里面用的是5.6.0版本,现在记录下使用json作为数据源的操作步骤。这个图文教程超级详细,是__馋猫原创真的是原创

一、首先,创建json数据源。点击【Report Datasources】-----》【new】-----》选择【Json Datasources】,填写名字,选择json文件路径即可,操作如下图:

二、添加field,添加field主要有两种方法,第一种,在操作窗口右键添加;第二种,在xml模式下,使用代码添加;如下图所示:

三、查询数据,测试field,查询数据的带入如下图所示测试之前先将步骤二里面添加的field拖拽到Detail里面,如下图所示

点击预览,结果如下图:

这里给出json文件、和报表的xml文件代码

本文版权归__馋猫和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。

{
    "glossary": {
        "title": "example glossary",
         "GlossDiv": {
                     "title": "S",
                  "GlossList": {
                                  "GlossEntry": {
                                      "ID": "SGML",
                          "SortAs": "SGML",
                      "GlossTerm": "Standard Generalized Markup Language",
                      "Acronym": "SGML",
                      "Abbrev": "ISO 8879:1986",
                      "GlossDef": {
                                          "para": "A meta-markup language, used to create markup languages such as DocBook.",
                      "GlossSeeAlso": ["GML", "XML"]
                                      },
                      "GlossSee": "markup"
                                  }
                              }
                }
    }

}
new1.json
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <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="dd016702-667b-495c-b3fc-10bbf5465ca0">
 3     <property name="ireport.zoom" value="1.0"/>
 4     <property name="ireport.x" value="0"/>
 5     <property name="ireport.y" value="0"/>
 6     <property name="net.sf.jasperreports.json.source" value="F:UserswenboDesktop
ew1.json"/>
 7     <queryString language="json">
 8         <![CDATA[glossary]]>
 9     </queryString>
10     <field name="field1" class="java.lang.String">
11         <fieldDescription><![CDATA[title]]></fieldDescription>
12     </field>
13     <background>
14         <band splitType="Stretch"/>
15     </background>
16     <title>
17         <band height="79" splitType="Stretch"/>
18     </title>
19     <pageHeader>
20         <band height="35" splitType="Stretch"/>
21     </pageHeader>
22     <columnHeader>
23         <band height="61" splitType="Stretch">
24             <staticText>
25                 <reportElement x="127" y="41" width="100" height="20" uuid="70124e49-1896-452c-a870-2e6d3b5731e8"/>
26                 <text><![CDATA[Title]]></text>
27             </staticText>
28         </band>
29     </columnHeader>
30     <detail>
31         <band height="125" splitType="Stretch">
32             <textField>
33                 <reportElement x="127" y="12" width="100" height="20" uuid="23c5cd26-652f-4fcf-bc56-6136cc0717ba"/>
34                 <textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression>
35             </textField>
36         </band>
37     </detail>
38     <columnFooter>
39         <band height="45" splitType="Stretch"/>
40     </columnFooter>
41     <pageFooter>
42         <band height="54" splitType="Stretch"/>
43     </pageFooter>
44     <summary>
45         <band height="42" splitType="Stretch"/>
46     </summary>
47 </jasperReport>
report1
原文地址:https://www.cnblogs.com/chanmao--/p/6393515.html