C++学习笔记-利用rapidJSON生成JSON数据
发布日期:2021-06-30 10:57:32
浏览次数:3
分类:技术文章
本文共 728 字,大约阅读时间需要 2 分钟。
RapidJSON is a header-only C++ library
在json.org中下载rapidjson
无需加dll和lib,只要加上头文件即可!
结构图如下:
源码如下:
#include "rapidjson/document.h"#include "rapidjson/writer.h"#include "rapidjson/stringbuffer.h"#include#include using namespace std;using namespace rapidjson;string toString(const Document& d){ StringBuffer buffer; Writer writer(buffer); d.Accept(writer); string str = buffer.GetString(); return str;}int main() { Document d; Document::AllocatorType& allocator = d.GetAllocator(); d.SetObject(); d.AddMember("id", 10086, allocator); d.AddMember("name", "中国移动", allocator); d.AddMember("login", true, allocator); string str = toString(d); printf(str.c_str()); getchar(); return 0;}
程序运行截图如下:
转载地址:https://it1995.blog.csdn.net/article/details/83963916 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月22日 06时17分12秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
C++ Core Guideline 笔记02
2019-04-30
C++ Core Guideline 笔记03
2019-04-30
C++11 C++14 C++17 move semantics
2019-04-30
octomap 简单自定义 OcTree
2019-04-30
numba nopython mode 不支持numpy.int类型
2019-04-30
安装测试CGAL和read_ply()
2019-04-30
A Tour of C++笔记
2019-04-30
ROS camera_calibration 源码阅读笔记
2019-04-30
kornia 之一 基础和 filter
2019-04-30
最近使用的一些用于点云和面网格处理的 CGAL 功能
2019-04-30
C++活到老学到老 auto
2019-04-30
CppWeekly 02,Fabonacci, exchange
2019-04-30
CppWeekly 04 if constexpr, if initialization
2019-04-30
CppWeekly 05 nested namespace and std::clamp
2019-04-30
CppWeekly 06 structured binding
2019-04-30
CppWeekly 08 constexpr
2019-04-30
CppWeekly 09 regex ( string_view )
2019-04-30