I am going to be consuming real time twitter feed and parsing it into objects for list view display. I need robust solution is default json lib good enough for this task or do I need to use Gson / jackson lib?
Check Gson and JackSon:
GSON
JACKSON
EDIT: I did not see you mention this libraries. Yes, you should use them. This are robust
libraries, I used them to consume Json webservices and no problem so far.
GSON/Jackson are just the libraries that allow you to parse json responses into objects or the other way round. However, the default implementation of json provided in android framework is capable enough of dealing any response string. The only drawback or turn-off is that you need to write extra code for simple things to get done.
Following are some links with bench marking of JSON libs...
http://blog.novoj.net/2012/02/05/json-java-parsers-generators-microbenchmark/
http://danielywoo.blogspot.in/2011/04/json-java-libraries-benchmark-jsonlib.html
Jackson Vs. Gson
And from the benchmark it looks like Jackson is the best and the fastest library for the JSON parsing...
Related
I have an application where I use Jsoup to get HTML file from the internet and parse it into POJOs. I use a custom Content Provider then to persist my POJOs into an SQLite database. It's a lot of code, and certain things are tricky to implement, caching especially (i.e. how to determine that my object is already in database, how to manage expiration, etc.). From looking over the internet I understood that RoboSpice might come to the rescue, since in handles caching transparently. However, I haven't found any example on how to plug in custom parser (my results are neither JSON nor XML, just pure HTML which I'm parsing with Jsoup currently). I'd therefore appreciate if you could point me to some related example.
Here's a more detailed description of what I'm doing. My app reads certain website to get the lists of certain entries. Those entries are calendar-based, and I'm requesting them month by month. Every month's request returns me a list of entries from that month. I want to make those requests cacheable and queryable, therefore I need a database backend, so that I can run custom SQL queries against it. Which RoboSpice configuration should I use, which extensions, and which code samples could I refer to?
Thanks in advance.
It looks like a good idea to use RoboSpice here, but the way you want to use is a bit out of its natural scope.
Usually people annotation a Pojo, let's say for Jackson, and they request a webservice, then the result is parsed via jackson and you get your Pojo. RoboSpice will simply reformat your pojo into json using jackson as parsing / formatting is a considered a bijection.
In your case, you will have to call your own ObjectPersister for your Pojo class and take care of its persistence format yourself. As you store your pojos into a database, the RoboSpice ormlite module may help but it is still experimental.
Have a look at the sample of the ormlite module of RoboSpice.
I want to parse a large JSON. How can I make it faster? Now it takes a lot of time. Please help me.
you can use some wrappers like http://code.google.com/p/json-simple/ it is optimised to handle large data from json and easy to use.
Also you can give it try to http://code.google.com/p/json-simple/ for better performance.
Following are the others.
Android built-in: http://developer.android.com/reference/org/json/package-summary.html
JSON.simple: http://code.google.com/p/json-simple/
Jackson: http://jackson.codehaus.org/
Gson: http://code.google.com/p/google-gson/
You can check comparison article over here.
According to some benchmarks Jackson is the fastest.
Use jackson JSON processor http://jackson.codehaus.org/
Most of the time people end up parsing the whole JSON and ignoring most of the data. This makes the process slow. If you are going to discard a lot of data, parsing in SAX mode is much faster, since you can stop parsing as soon as you have found all the required data.
Is it possible to parse json in parts when it was still downloaded?
For example I load a long json array with a very slow Internet. Can I download a part of text, parse it, add to screen, download next part and so on?
Check out the following SO question it has a few answers, but generally the consensus seems to be that you can depending on the package you are using. I have used GSON (Mentioned in the answers) but have never tried the incremental streaming feature.
GSON makes a lot of things much easier in general though, so I would check that out first if the other things GSON offers seem like a plus to whatever you are trying to do.
I'm curious whether it's more convenient to use json or xml in my android applications? Or does it not matter?
In Flash apps it's definitely more convenient to use xml, but in javascript (at least in my opinion), it's more convenient to work with json. I have a rails backend that could conveniently give json or xml so I'm trying to make a choice now.
Well the reason i ll recommend JSON not easy of use but the network bandwidth. JSON msgs are smaller in size as compared to XML. So consider this also for choosing one over the other.
Secondly, you can use Gson another lib also to ease your implementation which is easier to use as compared to org.json implementation that comes with Android platform.
JSON would be very easy in Android. You already have libraries for it, whose Classes you can use to parse the JSON file or content.
There is some pain involved in parsing XML. I would suggest JSON. Let me know if you need any examples of parsing using JSON.
Android SDK has both org.json or org.xml package so i think it is not a matter of Android sdk, but of your application/api design
JSON is very easy to use as comparing to XML.Android has support for both JSON and XML.A detailed example is already given here.This talks about when you go for JSON and XML
http://www.ibm.com/developerworks/xml/library/x-andbene1/
Hope this will help you.
I am a newbie in Android , I am doing a project where json parsing is done by calling a URL. I am able to do this by using built-in json parser provided by android.
But when i try to parse huge json response ,it fails. I got to know about another parser, "Jackson parser".
I googled a lot,but with no luck.
So , can anybody suggest me a way to parse json using Jackson parser through url?
OR
Provide me some example links, if possible?
I think, It will be helpful to other newbies like me.
You might want to give the package org.json a try. It is provided directly from the Android sdk.
JSONObjects can directly be parsed and provided to your objects i.g. via the constructor.
Try using thed Gson lib to deserialize json objects. Less painful to use, and it supports large objects quite well.