What is the practical difference between xml, json, rss and atom when interfacing with Twitter?

有些话、适合烂在心里 提交于 2019-12-03 14:49:46

For me it boils down to convenience. Using XML, I have to parse the response in to a DOM (or more usually an ElementTree). Using JSON, one call to simplejson.loads(json_string) and I have a native Python data structure (lists, dictionaries, strings etc) which I can start iterating over and processing. Anything that means writing a few less lines of code is usually a good idea in my opinion.

I often use JSON to move data structures between PHP, Python and JavaScript - again, because it saves me having to figure out an XML serialization and then parse it at the other end.

And like jinzo said, JSON ends up being slightly fewer bytes on the wire.

You might find my blog entry on JSON from a couple of years ago useful: http://simonwillison.net/2006/Dec/20/json/

RSS and Atom are XML formats.

JSON is a string which can be evaluated as Javascript code.

jinzo

I would say the amount of data being sent over the wire is one factor. XML data stream will be bigger than JSON for the same data. But you can use whatever you know more/have more experience.

I would recommend JSON, as it's more "pythonic" than XML.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!