views:

199

answers:

2

Hi,

In the Android application I am building, I want to be able to communicate with a local server developed in Django. (Basically a login page and a home page populated with posts and images from users) So do I need to use XML Parsers for the parsing the response from a Django server or is it possible for the server to respond with strings which can be directly used? Also what about images?

Is the JSON or XML Parser easier and robust to use in Android? The responses would be basically like tweets with a username, image and message. I was thinking of using the SAXParser. Any better alternatives?

Regards,

Primal

+1  A: 

Android has built in libraries for parsing both JSON and XML.

In my opinion, the easier (and better) one would probably JSON if you're just looking to output the serialized version of your models.

Some relevant links:

JSON:

http://developer.android.com/intl/zh-CN/reference/org/json/JSONObject.html

XML:

http://developer.android.com/intl/zh-CN/reference/org/xmlpull/v1/XmlPullParser.html http://developer.android.com/intl/zh-CN/reference/javax/xml/parsers/package-summary.html

Edit: In response to the last part of your question, yes, you can just output strings. Depending on the complexity of your data, you'll end up making things harder for yourself. Parsing JSON on Android is super easy. Just do it.

synic
Hmm. I am developing a microblogging platform with android interface. So I was thinking of using xml for transporting messages in this way<post><username>username</username><message>microblog</message><image>imageurl</image></post>And use a SAXParser to parse this response in Android and populate the views. Would JSON make it easier to send and parse responses??
primalpop
Yes, I think it would be easier to use JSON. See here: http://pastie.org/952207
synic
A: 

SAXParser is very easy to use, it just calls a method when it enters a node with the name of the node and its arguments. So yes, using SAX is a good idea.

Moons
Is it necessary that the data sent to the server should be xml formatted?
primalpop