JSON (JavaScript Object Notation) 用于存储和传输数据,通常用于服务器-->Web端的数据传输
JSON 示例:
{
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
}
JSON语法:
- Json文件的数据格式为key-value pair(键值对)
- key为字符串(双引号)
- value可以是字符串/数字(整型或浮点型)/布尔型(true/false)/null/数组/Object
- 不同的key-value pair之间用逗号
,
分隔 - {花括号}中为Object (key-value pair的value可以是key-value pair)
- [方括号]中为array数组 (数组的长度可以为1)
Cpp-Json解析
- nlohmann/json
- Tencent/rapidjson
- picojson
参考资料
- What is JSON (w3schools.com)
- A Beginner's Guide to JSON with Examples (attacomsian.com)
- Tencent/rapidjson: A fast JSON parser/generator for C++ with both SAX/DOM style API (github.com)