YAML和JSON有什么区别? [英] What is the difference between YAML and JSON?
问题描述
YAML和JSON有什么区别,特别考虑以下几点?
What are the differences between YAML and JSON, specifically considering the following things?
- 性能(编码/解码时间)
- 内存消耗
- 表达清晰度
- 图书馆的可用性,易用性(我更喜欢C)
我打算在嵌入式系统中使用这两者之一来存储配置文件.
I was planning to use one of these two in our embedded system to store configure files.
推荐答案
从技术上讲,YAML是JSON的超集.这意味着,至少从理论上讲,YAML解析器可以理解JSON,但不一定非要反过来.
Technically YAML is a superset of JSON. This means that, in theory at least, a YAML parser can understand JSON, but not necessarily the other way around.
请参阅标题为"YAML:与JSON的关系"的部分中的官方规范.
.通常,我喜欢某些关于YAML的东西,这些东西在JSON中不可用.
In general, there are certain things I like about YAML that are not available in JSON.
- @jdupont指出,YAML在外观上更易于查看.实际上, YAML主页本身就是有效的YAML,但是对于人类来说,它很容易阅读.
- YAML能够使用锚"引用YAML文件中的其他项目.因此,它可以处理在MySQL数据库中可能发现的关系信息.
- YAML在将其他序列化格式(例如JSON或XML 内)嵌入到YAML文件中时更加强大.
- As @jdupont pointed out, YAML is visually easier to look at. In fact the YAML homepage is itself valid YAML, yet it is easy for a human to read.
- YAML has the ability to reference other items within a YAML file using "anchors." Thus it can handle relational information as one might find in a MySQL database.
- YAML is more robust about embedding other serialization formats such as JSON or XML within a YAML file.
在实践中,最后两点对您或我所做的事情都不重要,但从长远来看,我认为YAML将是一种更健壮和可行的数据序列化格式.
In practice neither of these last two points will likely matter for things that you or I do, but in the long term, I think YAML will be a more robust and viable data serialization format.
目前,AJAX和其他网络技术倾向于使用JSON.目前,YAML被更多地用于脱机数据处理.例如,默认情况下,它包含在基于C的OpenCV计算机视觉软件包中,而JSON不包含在其中.
Right now, AJAX and other web technologies tend to use JSON. YAML is currently being used more for offline data processes. For example, it is included by default in the C-based OpenCV computer vision package, whereas JSON is not.
您将找到JSON和YAML的C库. YAML的库往往是较新的,但过去我对它们没有遇到任何麻烦.例如,参见 Yaml-cpp .
You will find C libraries for both JSON and YAML. YAML's libraries tend to be newer, but I have had no trouble with them in the past. See for example Yaml-cpp.
这篇关于YAML和JSON有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!