开发者

How to parse responses from a Django server in android?

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 wi开发者_JS百科th 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


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:

https://developer.android.com/reference/org/json/JSONObject.html

XML:

https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html https://developer.android.com/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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜