JSONObject/JSONArray API in Codename One

425 views
Skip to first unread message

Pai Peng

unread,
Jul 16, 2013, 3:35:39 PM7/16/13
to codenameone...@googlegroups.com
Hello all,


I would like to use the JSONObject and JSONArray in Codename One project for creating JSON string. I have tested json-simple Java library(https://code.google.com/p/json-simple/), it works great on Simulator, but not possible on Android or iOS device.
I have also tried to compile the json-simple source code in my project, but got error StringReader class not found.

Now I want to ask, How can I do this job under Codename One?

Thank you all.


Regards,

Pai

Steve Hannah

unread,
Jul 16, 2013, 3:38:57 PM7/16/13
to codenameone...@googlegroups.com
I have used this one with very few modifications in CN1 projects.

For performance reasons, I changed StringBuffer to StringBuilder, Hashtable to HashMap, and Vector to ArrayList throughout the library.  (This increases performance by a factor of 3.5 on iOS)

I don't have my changes handy right now, but I'll post them when I get a chance.

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/229ce175-85ac-4e24-ae2f-43ec3b5edb75%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Steve Hannah
Web Lite Solutions Corp.

Pai Peng

unread,
Jul 17, 2013, 3:51:37 AM7/17/13
to codenameone...@googlegroups.com
Hello Steve,

thank you very much for the helpful quick answer.

I have just tested this j2me-json. It works on simulator and also on iOS (iPod Touch device), but I get error "not installed" by installation on Samsung Galaxy S1 (Android 2.3.5).

How can I get the exact error message on Android? Or What else do I need to handle the source code of j2me-json in codename one?


Regards,

Pai

Pai Peng

unread,
Jul 17, 2013, 4:05:06 AM7/17/13
to codenameone...@googlegroups.com
Hello all,

j2me-json works now also on my Samsung Galaxy S1 Android 2.3.5 device. I don't know if the browser did download the correct version from Codename One server or not, but I have just deinstalled the old app and downloaded it again. It can be installed now.

Thank you Steve!

Regards,

Pai


On Wednesday, July 17, 2013 9:51:37 AM UTC+2, Pai Peng wrote:
Hello Steve,

thank you very much for the helpful quick answer.

I have just tested this j2me-json. It works on simulator and also on iOS (iPod Touch device), but I get error "not installed" by installation on Samsung Galaxy S1 (Android 2.3.5).

How can I get the exact error message on Android? Or What else do I need to handle the source code of j2me-json in codename one?


Regards,

Pai

On Tuesday, July 16, 2013 9:35:39 PM UTC+2, Pai Peng wrote:

Shai Almog

unread,
Jul 17, 2013, 11:56:40 AM7/17/13
to codenameone...@googlegroups.com
If you send a debug build or a build without a certificate a certificate will be generated randomly for you. This will allow you to install the app but won't allow you to upgrade it since the next certificate will have a different signature.

Jérémy MARQUER

unread,
Jul 26, 2016, 10:40:29 AM7/26/16
to CodenameOne Discussions
Hi all,

Steve, I think what you have mentionned here is very interesting... We don't have so much informations (dev guide, forum...) about performances on iOS related to Java Objects. It's very abstract since we don't know exactly how java object are converted in objective C. 

I know in Java difference between StringBuffer/Builder, Hashtable/HashMap etc but it's pretty difficult to apply this to ios platform. You said that replacing some java object "increase performance by a factor of 3.5" on iOS : how did you the benchmark ? I think it could be interesting to have more documentation about performance linked to the platform.

Thanks,

Jérémy.


Le mardi 16 juillet 2013 21:38:57 UTC+2, shannah a écrit :
I have used this one with very few modifications in CN1 projects.

For performance reasons, I changed StringBuffer to StringBuilder, Hashtable to HashMap, and Vector to ArrayList throughout the library.  (This increases performance by a factor of 3.5 on iOS)

I don't have my changes handy right now, but I'll post them when I get a chance.

Steve
On Tue, Jul 16, 2013 at 12:35 PM, Pai Peng <sipa...@gmail.com> wrote:
Hello all,


I would like to use the JSONObject and JSONArray in Codename One project for creating JSON string. I have tested json-simple Java library(https://code.google.com/p/json-simple/), it works great on Simulator, but not possible on Android or iOS device.
I have also tried to compile the json-simple source code in my project, but got error StringReader class not found.

Now I want to ask, How can I do this job under Codename One?

Thank you all.


Regards,

Pai

--
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.

Jérémy MARQUER

unread,
Jul 26, 2016, 11:07:03 AM7/26/16
to CodenameOne Discussions
For example : 

JSONObject object = new JSONObject(json);

JSONArray arrayOfObjects = index.getJSONArray("myObjects");

With an array of about 3700 object --> This block takes 300 ms to execute in the simulator instead of  5 SECONDS on ios ...

Steve Hannah

unread,
Jul 26, 2016, 11:19:24 AM7/26/16
to codenameone...@googlegroups.com
On Tue, Jul 26, 2016 at 7:40 AM, Jérémy MARQUER <jrmy...@gmail.com> wrote:
Hi all,

Steve, I think what you have mentionned here is very interesting... We don't have so much informations (dev guide, forum...) about performances on iOS related to Java Objects. It's very abstract since we don't know exactly how java object are converted in objective C. 
It is converted to C, not objective C.  You're right.  There isn't that much info in the dev guide.  Performance will vary on what you are doing.  Some things are highly optimized as they fall in critical code paths that we needed to pay close attention to.  Some use-cases may not be as optimized.  Generally, if I see a case that produces poor performance, I'll look at the C code that is generated and see if there is anything I can do to improve it.  In some cases the solution is to just implement a couple of critical methods directly in C.  Other times I decide to tweak how ParparVM actually generates C for a particular code pattern.  Xcode has fairly decent profiling tools to make this sort of analysis possible.

But.... Warning, this type of optimization is not for the faint of heart.  Performance should already be quite good for most apps.  I would look here *only* as a last resort after you've gone through your own code and found any bottlenecks.  Java IDEs provide lots of great profiling tools that will allow you to identify bottlenecks well before you hit the device.
 

I know in Java difference between StringBuffer/Builder, Hashtable/HashMap etc but it's pretty difficult to apply this to ios platform. You said that replacing some java object "increase performance by a factor of 3.5" on iOS : how did you the benchmark ? I think it could be interesting to have more documentation about performance linked to the platform.

Those benchmarks were done a few years ago when we were using the XMLVM back-end.  XMLVM was *very* slow with object locking/synchronization.  Knowing this, I was able to get dramatic performance increases by replacing Hashtable with Hashmap (etc).  ParparVM has much better synchronization performance so such gains don't exist at the same level.  You can still get marginal gains by choosing classes and structures that aren't thread-safe, but not like on XMLVM.  
That's not really a fair comparison.  The desktop has so much more processing power than a hand-held device.  a factor of 12 is actually quite a reasonable difference in processing time.  A better comparison would be to parse these on the same device using different mechanisms (e.g. with standard C, or with another VM like RoboVM, Avian, XMLVM, or Zero). 

Steve

Jérémy MARQUER

unread,
Jul 28, 2016, 3:32:35 AM7/28/16
to CodenameOne Discussions
Ok thanks for explanations !

I wasn't thinking there is a factor of 12 between computer and mobile devices oO
Reply all
Reply to author
Forward
0 new messages