C++之RapidJSON解析json数据

博客介绍了RapidJSON,它是一个C++的JSON解析器及生成器。提到复制JSON文本可能出错,可将其复制到JSON在线编辑器验证,还涉及解析代码和输出结果等内容,重点是C++利用RapidJSON生成JSON数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值