先决条件:
- JSON
- XML |基本
JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,它完全独立于语言。它基于 JavaScript 编程语言,易于理解和生成。
例子 :
{"Geeks":[
{ "firstName":"Vivek", "lastName":"Kothari" },
{ "firstName":"Suraj", "lastName":"Kumar" },
{ "firstName":"John", "lastName":"Smith" },
{ "firstName":"Peter", "lastName":"Gregory" }
]}
XML(可扩展标记语言)旨在承载数据,而不是显示数据。这是 W3C 的建议。可扩展标记语言 (XML) 是一种标记语言,它定义了一组规则,用于以人类可读和机器可读的格式对文档进行编码。 XML 的设计目标侧重于 Internet 上的简单性、通用性和可用性。它是一种文本数据格式,通过 Unicode 为不同的人类语言提供强大的支持。尽管 XML 的设计侧重于文档,但该语言广泛用于表示任意数据结构,例如 Web 服务中使用的数据结构。
例子 :
Vivek Kothari
Suraj Kumar
John Smith
Peter Gregory
这两者都是自描述的,可以被许多编程语言解析和使用。
以下是 JSON 和 XML 之间的一些区别:
JSON | XML |
---|---|
It is JavaScript Object Notation | It is Extensible markup language |
It is based on JavaScript language. | It is derived from SGML. |
It is a way of representing objects. | It is a markup language and uses tag structure to represent data items. |
It does not provides any support for namespaces. | It supports namespaces. |
It supports array. | It doesn’t supports array. |
Its files are very easy to read as compared to XML. | Its documents are comparatively difficult to read and interpret. |
It doesn’t use end tag. | It has start and end tags. |
It is less secured. | It is more secured than JSON. |
It doesn’t supports comments. | It supports comments. |
It supports only UTF-8 encoding. | It supports various encoding. |