Hello,
Is it possible to print JSON in a Java Agent?
Instead of returning XML, I would like to return JSON, but I don’t know how to do it.
Can somebody help?
I need something to help me get started.
Thanks a lot!
Hello,
Is it possible to print JSON in a Java Agent?
Instead of returning XML, I would like to return JSON, but I don’t know how to do it.
Can somebody help?
I need something to help me get started.
Thanks a lot!
Subject: I do this in LotusScript…
Build a comma-separated string of key:value for each JSON element. That is, in the LS I append +“:”+ to a string, with commas as required after the first. Let’s call this kvOut.
Print the following:
header=|Content-Type: application/json|+Chr$(13)+Chr$(10)
header=header+|Cache-Control: no-cache|+Chr$(13)+Chr$(10)
Print header+|{ |+kvOut+| }|
Hope this helps…
Subject: Print JSON in a Java Agent?
Thanks, it does help.
So if I understand correctly, you are generating your JSON using a string?
I was wondering if there’s a way to generate JSON using some Java classes?
Subject: Easy way I would do it.
Although it depends on what you are trying to pass back.
If you passing back one or more records then have them display in a view and pass back the view URL formatted in JSON.
See the following for details.
Subject: dojo.xhdr understands it on return from the AJAX call.
Print ajax.toJSON
As far as classes go it’s pretty simplistic, but that doesn’t mean something Java doesn’t already exist. It just means if you can’t find it, it should take about an hour to whip it together. JSON is just a string no matter what manipulates it.
Hope this helps…
Subject: Thanks for your help!
It works!
Subject: Sweet!..
Subject: Some JSON Java Libraries
Just in case it might help somebody, I found a couple of good JSON Java libraries.
I started by using this one:
http://www.json.org/java/index.html
It’s a really simple one and it’s working well.
I however switched to the Google GSON:
It’s simple too, but way more complete.
For instance, I can convert a Java object directly to JSON. Very cool!