How to do: JSONParser Map

26 views
Skip to first unread message

rava...@gmail.com

unread,
Oct 7, 2015, 5:55:35 AM10/7/15
to CodenameOne Discussions
Hi,
i have a webservice that return a JSON.

The structure of the JSON is:

[{"name":"propriety1", "otherName":"otherProprieties1"},{"name":"propriety2","otherName":"otherProprieties2"},{"name":"propriety3", "otherName":"otherProprieties3"},...,{"name":"proprietyN", otherName":"otherProprietiesN"}]

I do this for parse:

byte b[] = Util.readInputStream(input);
input = new ByteArrayInputStream(b);
JSONParser jp = new JSONParser();
Map m = jp.parseJSON(new InputStreamReader(input));

but i don't know how to get an object from the map (i don't know the key) and get the item from the object

Can someone help me?

Steve CN1 Hannah

unread,
Oct 7, 2015, 2:56:53 PM10/7/15
to codenameone...@googlegroups.com
Since your JSON is an array, you will find the array with m.get("root").  That will return a List of Maps.

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/b755bbdc-7e21-4944-baae-0604567de0d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One

rava...@gmail.com

unread,
Oct 8, 2015, 3:08:52 AM10/8/15
to CodenameOne Discussions
Thank you very much!
It works!


On Wednesday, October 7, 2015 at 8:56:53 PM UTC+2, Steve CN1 Hannah wrote:
Since your JSON is an array, you will find the array with m.get("root").  That will return a List of Maps.

Steve
On Wed, Oct 7, 2015 at 2:55 AM, <rava...@gmail.com> wrote:
Hi,
i have a webservice that return a JSON.

The structure of the JSON is:

[{"name":"propriety1", "otherName":"otherProprieties1"},{"name":"propriety2","otherName":"otherProprieties2"},{"name":"propriety3", "otherName":"otherProprieties3"},...,{"name":"proprietyN", otherName":"otherProprietiesN"}]

I do this for parse:

byte b[] = Util.readInputStream(input);
input = new ByteArrayInputStream(b);
JSONParser jp = new JSONParser();
Map m = jp.parseJSON(new InputStreamReader(input));

but i don't know how to get an object from the map (i don't know the key) and get the item from the object

Can someone help me?

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages