#1 2017-05-11 15:46:37

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

[SOLVED] Filling a Report from a JSON String ?

Hello David and other friends,

I am at that time where the brain is lost by many hours of trials : I am looking for a way to fill a Report from a String and don't understand why it is not working with the example attached (I swear to have searched the examples provided with AB).

On that example, I have a button at the left which serializes / unserializes the content of an Array that I would like to use to feed the Report1.Data. The console shows that Report1.Data is the String I provide.

With the button at the right, I only feed the Report1.Data from code (example provided in the Help file). In the console, I can see that Report1.Data is composed of two Objects.

But why doesn't it work when I provide the String as data because it does work when you provide a file in the Report1.Url ? It is a string too. I am a large bit lost

Many thanks for any reply  tongue


testFeedJSON.ab

Last edited by svanneste (2017-05-12 10:54:07)

Offline

#2 2017-05-11 16:50:42

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: [SOLVED] Filling a Report from a JSON String ?

Well, perhaps is this because I feed the report with

{"ID":1,"Name":"John"},{"ID":2,"Name":"Abel"}

instead of

[{"ID":1,"Name":"John"},{"ID":2,"Name":"Abel"}]

but I am unable to add the closing bracket "]" (and accessory I have lost the page of the special characters in the help file)... I need some rest smile

Offline

#3 2017-05-11 17:31:57

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: [SOLVED] Filling a Report from a JSON String ?

No,

[{"ID":1,"Name":"John"},{"ID":2,"Name":"Abel"}]

won't work either...

Oh, I noticed that we seem to have lost :

If you check the Watcher "Add app variables" checkbox then App Builder add to the debugger watcher app variables created by the SetVar, NewArray and NewObject actions.

Removing, adding the Watcher again seems to work btw

Last edited by svanneste (2017-05-11 17:53:48)

Offline

#4 2017-05-11 19:18:01

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: [SOLVED] Filling a Report from a JSON String ?

Hello Samuel,

Please, take a look at the attached sample, which is a modification of your own one. Take a look in particular at the "Button3" (From string) Click event. As you can see, we can deal with objects directly, that is, we no need to serialize nothing, but, just add any number of objects into the Report's Data variable.

Download the modified sample from here

Please, let me know if you have any further question!

Offline

#5 2017-05-11 20:11:58

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: [SOLVED] Filling a Report from a JSON String ?

Hello David,

Thanks a lot for your support and the example provided. The problem I still have with that example is this one : I receive the JSON from a server but would like to encrypt it (make a packet that I will decrypt when received). So, I have the String, not the objects in a list (an array) ordered.
It is inside a browser app so I can not use the File plugin (I think) and so I can not reload a clear save file. And I can not imagine (at the moment, probably tired on this), recreating objects reading from the JSON string.

Please, forgive me if I am not clear enough and thanks a lot for your help. I will try again tomorrow on the project. All my bests, David smile

Last edited by svanneste (2017-05-11 20:12:40)

Offline

#6 2017-05-11 20:51:01

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: [SOLVED] Filling a Report from a JSON String ?

Hello Samuel,

Please, take a look at this sample:

Download the sample from here

The sample uses the CryptoJS library to encrypt some JSON string. We have saved that JSON in an app's local file, but, we can also retrieve it from a remote service. In any case we must decrypt the source (encrypted) string, and then, serialize the string to convert it to an Array of objects, that we can directly set to the Report's Data variable.

Offline

#7 2017-05-12 10:58:27

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: [SOLVED] Filling a Report from a JSON String ?

Hello David,
Thanks a lot for that new example. It is somewhat I wanted to create (but sending the javascript code to decrypt at random rates from the server ~I have already the related code).
But your example is fantastic too.
What I have learned from my researches since yesterday (and I was surprised) is that I have to unserialize (in the example I already provided) and create a new object then add it to the report, while I thought I could only provide the related data as if it was a json file.

But again, many thanks for your fantastic support and patience smile

Offline

#8 2017-05-12 11:38:35

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: [SOLVED] Filling a Report from a JSON String ?

Hello Samuel,

Always thanks to you sir. I am happy to help when possible! Certainly encrypt and decrypt data in these cases can have some sense, however, maybe a good HTTPS connection between the server and the app can do the job. Anyway, as you can see, we can encrypt, decrypt, serialize, unserialize, without problems, so, if you have any of them, just post it here and we will try to help. smile

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.