How I can use a JSON file to create a StiJsonDatabase

Stimulsoft Reports.JAVA discussion
Post Reply
xing kenny
Posts: 4
Joined: Mon Dec 19, 2016 11:20 am

How I can use a JSON file to create a StiJsonDatabase

Post by xing kenny »

hello!

I have read the topic 'Example of rendering a report with Java and Json?' viewtopic.php?f=19&t=54471
And I think the following codes should work.

report = StiSerializeManager.deserializeReport(new File("Data/AuDemo.mrt"));
File file = new File("Data/auDemo2.json");
StiJsonDatabase jsonDb = new StiJsonDatabase("Data", new File("Data/auDemo2.json"));
System.out.println(jsonDb.toString());
jsonDb.getJSONObject().keys().forEachRemaining( obj -> {
System.out.println(obj);
});
StiDatabaseCollection coll = new StiDatabaseCollection();
coll.add(jsonDb);
report.dictionary.setDatabases(coll);
report.setJsonReport(true);
report.render();

the json file like this

{
"Offers": [
{
"id": "5",
"subId": "5_1",
"name": "Offer 1",
"location": "City"
}
],
"Students": [
{
"id": "5",
"firstName": "Anne-Marie",
"lastName": "Abdula",
"schoolclassShort": "3a"
}
],
"Period": [{
"dateFrom": "22.08.2016",
"dateTo": "31.10.2016"
}]
}

but I got message as following , and cannot get anything in the report .


十二月 19, 2016 7:52:05 下午 com.stimulsoft.lib.utils.StiCollectionsUtil getElement
警告: Element named 'auDemo' missing
十二月 19, 2016 7:52:05 下午 com.stimulsoft.lib.utils.StiCollectionsUtil getElement
警告: Element named 'auDemo' missing
十二月 19, 2016 7:52:05 下午 com.stimulsoft.lib.utils.StiCollectionsUtil getElement
警告: Element named 'auDemo' missing
十二月 19, 2016 7:52:05 下午 com.stimulsoft.lib.utils.StiCollectionsUtil getElement
警告: Element named 'auDemo' missing
十二月 19, 2016 7:52:05 下午 com.stimulsoft.lib.utils.StiCollectionsUtil getElement
警告: Element named 'auDemo' missing
十二月 19, 2016 7:52:05 下午 com.stimulsoft.lib.utils.StiCollectionsUtil getElement
警告: Element named 'auDemo' missing
十二月 19, 2016 7:52:05 下午 com.stimulsoft.report.engine.parser.StiParser ParseTextValue
警告: Parser error: Syntax error - unprocessed lexemes remain, , , ,

My env is
macOS Sierra 10.12.1
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)

how to do that the StiJsonDatabase can be cteated OK ?
thanks
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: How I can use a JSON file to create a StiJsonDatabase

Post by Vadim »

Hello.
The JSON file & code is ok.
It's something wrong with your template .mrt file.
You can send us it for analyze.
xing kenny
Posts: 4
Joined: Mon Dec 19, 2016 11:20 am

Re: How I can use a JSON file to create a StiJsonDatabase

Post by xing kenny »

got it.

new StiJsonDatabase("Data", new File("Data/auDemo2.json"));

There the "Data" , first parameter of the StiJsonDatabase method , should same with the datasource's name that named in the designer.

thanks!
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How I can use a JSON file to create a StiJsonDatabase

Post by HighAley »

Hello.

We are always glad to help you.
Let us know if you need our help.

Thank you.
Post Reply