RapidJSON 是一个 C++ 的 JSON 解析器及生成器。
JSON文本:
//document.json
{"name":"xiaoming","gender":"boy","hobby":["足球","篮球","电影"],"socre":{"数学":91.5,"英语":96.0,"语文":95.5},"lover":{"name":"xiaohong","gender":"girl","hobby":["画画","跳舞","唱歌"],"score":{"数学":78.5,"英语":90.0,"语文":89.0}}}
由于复制的过程中,json文本可以出现错误,可以用将json文本复制到JSON在线编辑器验证一下。
解析代码:
#include<string>
#include<fstream>
#include<iostream>
#include"document.h"
using namespace std;
int main () {
std::ifstream t("./document.json");
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
rapidjson::Document document;
document.Parse(str.c_str());
rapidjson::Value::ConstMemberIterator iter = document.FindMember("name");
if(iter != document.MemberEnd()){
co