Remote reading on Android: Json or XML?

Asked

Viewed 138 times

2

I’m starting on Android and also don’t have much experience in Java. My first application will have a query to a remote server. My question is this::

In Android (consequently in Java) what is more practical, when it comes to obtaining the data: in Json or in XML?

2 answers

4

Briefly JSON is quite concise and easy to interpret by the machine. Already XML is more expressive, you can express complex dialects, however it is quite verbose in relation to JSON, so the representation of the same data set tends to be significantly higher.

Specifically for Java/Android there are great manipulation libraries for both formats, but if you do not know what to use I would recommend going with JSON because it is the simplest format.

2

I agree with Brunobr, XML is more verbose and with greater dialect possibilities than JSON, which in turn is simpler and easier to understand.

As for practicality, there are very good frameworks to deal with both, so I don’t see this as a criterion that strongly influences the decision of choice between one or the other. I would take more into consideration the conversion speed of XML-> Java and Java->XML in relation to the conversion speed of JSON->Java and Java->JSON and the size of the file that will be transferred from the web service to the application. On a mobile device with limited hardware and limited internet, any detail in performance makes a difference.

Has a post very good Thomas Uhrig comparing performance of Java frameworks dealing with JSON x Java frameworks dealing with XML. As a result of the tests carried out by him, the following conclusions were reached:

The first result of my tests was that the Jackson framework (JSON) writes data a little faster than the framework JAXB(XML) and the Gson(JSON) framework. The difference isn’t much.

The Java->XML and Java->JSON writing did not have much difference in performance between the 3, but said that Jackson performed the task a little faster than the other 2.

The most interesting is the fact that the two implementations of frameworks for JSON (Jackson and Gson) read much faster date than than JAXB.

He realized that reading JSON -> Java in the two frameworks was much faster than XML -> Java in the JAXB framework.

The JSON file was about 68% the size of the XML file correspondent.

If we put the same content in an XML file and a JSON file, the JSON file will be 68% lighter. Now, think about how this can make a total difference if we take into account the mobile internet that we have in our country. We need to take a lot into account the size of what will be transferred from web service to application, this is basic concept. It takes time to load a data set can make the user experience a bad experience. User does not like to wait, take it for me =D.

  • 1

    I forgot to comment, my web services are Restful, always return JSON and in my applications I use the Gson framework to handle the received JSON. Gson is a simple MUUUITO framework to handle. Hugging!

  • 1

    Great explanation of both, also always return JSON from my Webservices because I find it much easier to understand and write.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.