中国人似乎特别喜欢比较。总会有百无聊赖的提问:
哪种编程语言更好?
是写服务端好还是客户端好?
是Android好还是ios好?
是桌面端好还是移动端好还是网页端好?
等等……

我猜这样的人最后什么都学不成,更多的情况是C语言都不了解,一行代码不会写,就提出这样的问题。

============================================================
现在开始正文:

做c/s开发的人,即使你一定不懂JavaScript,那你也一定听说过JSON,也一定听说过XML。

这是两种人们常常采用的存储数据的格式。

那么国人的本性发作了:who is better?

JSON 和 XML谁更好呢? 谁更快呢?我到底该使用哪一个呢?就像比较自行车和汽车哪个更好一样?

先什么都不说,看个片段:

{"id": 110,"title": "Living or Die","author": "Wang Shubo","published": {"by": "gcd","year": 2016}
}
<?xml version="1.0"?>
<book id="110"><title>Living or Die</title><author>Wang Shubo</author><published><by>gcd</by><year>2016</year></published>
</book>

上面两个片段就是最基本的xml和json结构,谁能根据这个就判断who is better!!!
第一个片段共计140个字母,第二个片段167个字母,根据这个就能判断who is better?

再看看他们的优缺点:
JSON
优点:
Simple syntax, which results in less “markup” overhead compared to XML.
Easy to use with JavaScript as the markup is a subset of JS object literal notation and has the same basic data types as JavaScript.
JSON Schema for description and datatype and structure validation
缺点:
Simple syntax, only a handful of different data types are supported.
支持的数据类型少。

XML
优点:
Generalized markup; it is possible to create “dialects” for any kind of purpose
XML Schema for datatype, structure validation. Makes it also possible to create new datatypes
XSLT for transformation into different output formats
XPath/XQuery for extracting information (which makes getting information in deeply nested structures much easier then with JSON)
built in support for namespaces
缺点:
Relatively wordy compared to JSON (results in more data for the same amount of information).
支持更多的类型,可以添加更多的信息。

还有~
需要明确的是:
JSON is a good data format, and it is just a data format

所以,就是说很多情况下json是不能替代xml的:
XML is not a data format; it is a language. A very powerful one

从foreigner的一篇文章趴下来的理由:链接 http://www.yegor256.com/2015/11/16/json-vs-xml.html
XPath.
To get data like the year of publication from the document above, I just send an XPath query: /book/published/year/text(). However, there has to be an XPath processor that understands my request and returns 2004. The beauty of this is that XPath 2.0 is a very powerful query engine with its own functions, predicates, axes, etc. You can literally put any logic into your XPath request without writing any traversing logic in Java, for example. You may ask “How many books were published by David West in 2004?” and get an answer, just via XPath. JSON is not even close to this.

Attributes and Namespaces.
You can attach metadata to your data, just like it’s done above with the id attribute. The data stays inside elements, just like the name of the book author, for example, while metadata (data about data) can and should be placed into attributes. This significantly helps in organizing and structuring information. On top of that, both elements and attributes can be marked as belonging to certain namespaces. This is a very useful technique during times when a few applications are working with the same XML document.

XML Schema.
When you create an XML document in one place, modify it a few times somewhere else, and then transfer it to yet another place, you want to make sure its structure is not broken by any of these actions. One of them may use to store the publication date while another uses with ISO-8601. To avoid that mess in structure, create a supplementary document, which is called XML Schema, and ship it together with the main document. Everyone who wants to work with the main document will first validate its correctness using the schema supplied. This is a sort of integration testing in production. RelaxNG is a similar but simpler mechanism; give it a try if you find XML Schema too complex.

XSL.
You can make modifications to your XML document without any Java/Ruby/etc. code at all. Just create an XSL transformation document and “apply” it to your original XML. As an output, you will get a new XML. The XSL language (it is purely functional, by the way) is designed for hierarchical data manipulations. It is much more suitable for this task than Java or any other OOP/procedural approach. You can transform an XML document into anything, including plain text and HTML. Some complain about XSL’s complexity, but please give it a try. You won’t need all of it, while its core functionality is pretty straight-forward.

最后的最后,本想自己总结一下,但是在stackoverflow上看到了更好的,很到位:

如果你只是想简单的传递atomic values,json比xml好用了太多:json可以直接用在Internet上,被很多应用程序广泛的支持,而且可以写很简单的程序去处理json,json容易被创建,而且使用的是Unicode编码。

对于非结构化的数据,我们就要使用xml

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

彩蛋:
I’m not worried about the future of XML at all even if its death is gleefully celebrated by a cadre of web API designers.

And I can’t resist tucking an “I told you so!” token away in my desk. I look forward to seeing what the JSON folks do when they are asked to develop richer APIs. When they want to exchange less well strucured data, will they shoehorn it into JSON? I see occasional mentions of a schema language for JSON, will other languages follow? …

最后,看到了一个人说的比较有意思:
抵制xml的大多是Web Developers,而不是integration developers。

笑而不语~~

Comparing JSON and XML? Stop it!相关推荐

  1. 在.NET2.0中解析Json和Xml

    在.NET2.0中解析Json和Xml 在.NET解析json有很多方法,这里介绍最简单也用的最多的一种. 一.添加引用 解析Json,先下载开源控件 Newtonsoft.Json.dll 下载地址 ...

  2. ajax请求json和xml数据及对json和xml格式数据的解析

    ajax请求json和xml数据及对json和xml格式数据的解析 一.ajax请求json数据并解析 ajax的写法: json数据解析: 请求json经常出现的跨域报错: 二.ajax请求xml数 ...

  3. Java JSON、XML文件/字符串与Bean对象互转解析

    前言      在做web或者其他项目中,JSON与XML格式的数据是大家经常会碰见的2种.在与各种平台做数据对接的时候,JSON与XML格式也是基本的数据传递格式,本文主要简单的介绍JSON/XML ...

  4. SpringBoot使用教程【1】Restful API设计 返回json,xml格式...

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qingfeng812/article/details/74738885 效果展示: 浏览器截图 ht ...

  5. json execel xml 互转

    import xlwt import json import xlrd import xlrd import json import os from xml_and_json import * fro ...

  6. jackson (json、xml的序列化与反序列化)

    jackson用于java对象到json的序列化与反序列化.还支持xml格式. jackson用于实现json与java对象的序列与反序列化.web service要实现跨机器传送对象那么就需要有一种 ...

  7. .NetCore获取Json和Xml格式的配置信息

    本篇将和大家分享的是:如何获取Json和Xml格式的配置信息,主要介绍的是Configuration扩展方法的使用,因为netcore的web应用在Startup中已经默认嵌入appsettings. ...

  8. php如何返回数据请求数据格式化,PHP以json或xml数据格式返回请求数据的封装代码...

    现在主流的数据格式无非就是json和xml,下面我们来看看如何用php来封装一个返回这两种格式数据的类,下面青岛星网跟大家一起分享. 1.以json格式返回数据 json格式返回数据比较简单,直接将我 ...

  9. Dreamer 3.0 支持json、xml、文件上传

    自己写的框架,功能类似Struts2.x 下载地址:http://pan.baidu.com/share/link?shareid=3273223286&uk=470382596 新增功能: ...

  10. 快来看看Google出品的Protocol Buffer,别仅仅会用Json和XML了

    前言 习惯用 Json.XML 数据存储格式的你们,相信大多都没听过Protocol Buffer Protocol Buffer 事实上 是 Google出品的一种轻量 & 高效的结构化数据 ...

最新文章

  1. 深圳高一学生,夺冠国际物理奥赛
  2. CVPR 2014 ObjectnessBING 原文翻译
  3. 事务操作 mysql的事务操作
  4. SSH(Struts2+Hibernate+Spring)开发策略
  5. python创建sqlite3数据库_Python之Sqlite3数据库基本操作
  6. vue实现Excel文件的上传与下载
  7. JAVA 代码交互率低的原因分析,深入剖析Java编程中的中文问题及建议最优解决方法...
  8. [转]不知道能否解决先转下来再说不显示删除回复显示所有回复显示星级回复显示得分回复 没有找到MSVR90D.dll因此这个应用程序未能启动...
  9. PyTorch 入坑九:权重初始化
  10. [转] Android SDK manager 无法获取更新版本列表
  11. [原创]测试用例设计策略
  12. 视频中场的概念(1080I和1080P)和BT601/656/709/1120/2020/2077
  13. cacti mysql 压缩 备份_cacti数据迁移步骤 CactiEZ重装系统后 恢复原来的数据 CactiEZ重装系统前要备份的数据...
  14. Flask--网页微信登陆示例
  15. android 资源文件类型,命名规则(配置限定符名称),及其加载规则
  16. HY-SRF05 五针超声波测距模块 在stm32f4上实现 附代码 个人经验
  17. 2015年动漫电影观影指南值得收藏
  18. AG9300|Type-C 转VGA数据转换器解决方案
  19. Hadoop-kms总结
  20. 1685_Excel的几种脚本处理方式

热门文章

  1. 前端工程师的摸鱼日常(13)
  2. Unity3D进行项目build时的“Data folder not found”问题
  3. 下拉列表—DropDownMenu的使用解析
  4. Java 获取网络url图片返回file文件对象
  5. 华为人工智能atlasA800-9000物理服务器离线安装及CANN安装和MindSpore安装和Tensorflow安装
  6. 52 jQuery-使用fadeIn()和fadeOut()方法实现淡入淡出效果
  7. 自动化测试之:关键字驱动
  8. oracle_java.exe,系统找不到C:\ProgramData\Oracle\Java\javapath\java.exe问题及解决方案
  9. 浅论cherry机械键盘与其在war3中的表现
  10. 待办事项列表,敏捷项目管理的核心工件