JSONParser parse an array returned from server, not an object

64 views
Skip to first unread message

jo...@jdiligence.com

unread,
Aug 13, 2013, 5:15:29 PM8/13/13
to codenameone...@googlegroups.com
Taking a quick look at JSONparser in codename one and notice it seems to assume you want a json object into a hashtable.

The servers we are calling return json arrays for most requests. Any plan to add support for returning other types?

Shai Almog

unread,
Aug 14, 2013, 1:52:18 AM8/14/13
to codenameone...@googlegroups.com, jo...@jdiligence.com
It nests Hashtables and Vectors so it supports both.
We plan to modernize it a bit in the near future to use generified java.util.List & java.util.Map.

jo...@jdiligence.com

unread,
Aug 14, 2013, 8:02:17 AM8/14/13
to codenameone...@googlegroups.com, jo...@jdiligence.com
Maybe I am having a bad brain day, but I can't see how to get it to return an array as root. It assumes root state is a Hashtable. However I can see that I could write my own callback for it to do this for arrays.

Another suggested improvement is to strip any BOM characters in the stream as you go. We have had problems with some platforms inserting BOMs causing parser problems for the app. The workaround we did was read all into memory, strip them, then send to parser, but that defeats the whole point of a stream parser and wastes a lot of memory!!

Shai Almog

unread,
Aug 14, 2013, 1:14:58 PM8/14/13
to codenameone...@googlegroups.com, jo...@jdiligence.com
If the root is an array it will be packaged into the Hashtable as "root". Its the only special case.
The alternative would be to return Object which we didn't want to do.

jo...@jdiligence.com

unread,
Aug 14, 2013, 1:31:38 PM8/14/13
to codenameone...@googlegroups.com, jo...@jdiligence.com
Great. Thanks. Will do that. For the time being I have stuck with the old parser (which has specific types instead of mapping to standard ones like Hashtable), but will port to your one later.
Reply all
Reply to author
Forward
0 new messages