解析 json 构造二维表

【问题】

hi, i have this data :       data  =  [{“car”:“clear”,“number”:[“12”,“13”,“14”,“21”]},{“car”:“noClear”,“number”:[“34”]}]

i want to show like that in the report:

                                                                                clear

                                                                                12 13 14 21

                                                                                noClear

                                                                                34 

【回答】

将 number 序列转为空格分隔的字符串,即可构造规范的二维表,jasper 可据此设计简单列表呈现。可用 SPL 准备数据,代码简单:

A
1 =file(“d:\\data.json”).read()
2 =json(A1)
3 =A2.new(car,number.concat(" "):col)

运行结果:

A1:读取 json

A2:形成序表

A3:将 number 字段生成字符串用空格连接,生成新序表

Jasper 可以通过 JDBC 连接集算器,调用脚本方法和调用存储过程一样,详情参考【JasperReport 调用 SPL 脚本】。