与Twitter交互时,xml,json,rss和atom之间的实际区别是什么? [英] What is the practical difference between xml, json, rss and atom when interfacing with Twitter?

查看:114
本文介绍了与Twitter交互时,xml,json,rss和atom之间的实际区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web服务的新手,作为介绍,我正在使用python中的Twisted框架来处理Twitter API.我已经阅读了它们提供的不同格式,但是我仍然不清楚在我相当简单的项目中应该使用哪种格式. 具体来说,我想指导使用JSON或XML之间的实际区别.我要做的就是请求公共时间轴并将其缓存在本地.

I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project. Specifically the practical difference between using JSON or XML is something I'd like guidance on. All I'm doing is requesting the public timeline and caching it locally.

谢谢.

推荐答案

对我来说归结为方便.使用XML,我必须将响应解析为DOM(或更常见的是ElementTree).使用JSON,一个对simplejson.loads(json_string)的调用,我有了一个本地Python数据结构(列表,字典,字符串等),可以开始迭代和处理.在我看来,任何意味着减少几行代码的事情通常都是一个好主意.

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.

我经常使用JSON在PHP,Python和JavaScript之间移动数据结构-再次,因为它省去了我必须弄清楚XML序列化然后在另一端进行解析的麻烦.

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.

就像jinzo所说的那样,JSON最终在网络上的字节数要少一些.

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

您可能会发现几年前关于JSON的博客条目非常有用: http://simonwillison.net/2006/Dec/20/json/

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

这篇关于与Twitter交互时,xml,json,rss和atom之间的实际区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆