C++ JsonCpp库 源码编译及使用(VS2019)
下载JsonCpp库源码:
git clone git@github.com:open-source-parsers/jsoncpp.git
如果打不开可以试试:
git clone git@gitee.com:epson/jsoncpp.git
使用 cmake 界面版生成VS2019解决方案
打开生成的解决方案 jsoncpp.sln
生成动态库,注意选择需要的版本(debug/release)和平台(x64/x86)
生成静态库,注意选择需要的版本(debug/release)和平台(x64/x86)
简单测试(静态库):
需要用到的 jsoncpp_static.lib
以及头文件
#include <iostream>
#include "include/json/json.h"#ifndef _DEBUG
#else
#ifdef _WIN64
#pragma comment (lib,"lib/x64/Debug/jsoncpp_static.lib")
#else
#pragma comment (lib,"lib/x86/Debug/jsoncpp_static.lib")
#endif // _WIN64
#endifint main()
{Json::Value root;Json::Value value;Json::StreamWriterBuilder wbuilder;const std::unique_ptr<Json::StreamWriter> writer(wbuilder.newStreamWriter());value["id"] = 1;value["name"] = "Tom";root.append(value);value["id"] = 2;value["name"] = "Jerry";root.append(value);std::ostringstream json_str;std::cout << "Encode Json ===>" << std::endl;writer->write(root, &json_str);std::cout << json_str.str() << std::endl << std::endl;std::cout << "Decode Json ===>" << std::endl;JSONCPP_STRING err;Json::CharReaderBuilder rbuilder;const std::unique_ptr<Json::CharReader> reader(rbuilder.newCharReader());if (reader->parse(json_str.str().c_str(), json_str.str().c_str() + json_str.str().length(), &value, &err)){for (int i = 0; i < value.size(); i++) {const Json::Value o = value[i];int id = o["id"].asInt();std::string name(o["name"].asCString());std::stringstream _id;_id << id;std::cout << "id = " + _id.str() + "; name = " + name << std::endl;}}
}
测试代码:
epson/TestJsoncpp
C++ JsonCpp库 源码编译及使用(VS2019)相关推荐
- C++ Lua库 源码编译及使用(VS2019)
源码编译 官网下载源码: Lua: download 新建 空白解决方案 在该解决方案下新建空项目 lualib(编译静态库) 在该解决方案下新建空项目 luadll(编译动态库) 在该解决方案下新建 ...
- C++ LZ4库 源码编译及使用(VS2019)
下载LZ4库源码: git clone git@github.com:lz4/lz4.git 如果打不开可以试试: git clone git@gitee.com:epson/lz4.git 打开bu ...
- Jpeg-9e源码编译(Win10+VS2019)
源代码下载网址 Independent JPEG Group 下载后得到文件 解压缩到"D:\SourceCodes\jpeg-9e" 在目录"D:\SourceCode ...
- LibreCAD v2.2.0源码编译,使用VS2019+Qt5.12.9+Boost1.71.0环境
零.前言 LibreCAD is a fork of QCAD community edition version 2.0.5.0;therefore, any modifications of or ...
- 在Ubuntu 14.04 64bit上编译并研究State Threads网络线程库源码
State Threads是一个广受关注的高性能网络线程库,winlin在SRS中做了比较充分的应用,我很遗憾直到现在才精心研究它.下面是我的研究实录,以作备忘. 一.源码编译 下面是在Ubuntu ...
- python3 llvmlite源码_将Paddle-Lite在树莓派上源码编译及编译python预测库
新手使用Paddle-Lite 第一篇博客,第一次接触树莓派,把我的经历说一说. 一.为什么选Paddle-Lite? 因为我第一次接触人工智能,PaddlePaddle官网https://www.p ...
- java jni编译_从源码编译Android系统的Java类库和JNI动态库的方法
利用源码编译Android系统Java类库 1.编写Java项目和Android.mk文件 ├── Android.mk └── src └── com └── lhw └── framework └ ...
- python源码编译为库_【Python笔记】如何源码编译依赖LAPACK和ATLAS库的NumPy包
上篇笔记介绍了不依赖lapack和atlas库的NumPy包源码编译/安装方法,但"纯净版"的NumPy会损失性能,故本篇笔记说明如何源码编译安装依赖lapack和atlas库的N ...
- 解决源码编译Python3后缺少ssl tkinter,bz2等库的问题
Python3以后,使用源码编译python时默认不会包含ssl,tkinter等库,这意味着在调用"import _ssl"或者"import _tkinter&quo ...
最新文章
- [设计模式]原型模式
- MySQL 高级 - 存储过程 - 语法 - repeat循环
- excel大数据重采样批量操作(每两列中插入新一列,新一列为左右两列的平均值)
- 打印Show Attend and Tell的损失函数
- boost::hana::group用法的测试程序
- java应用cpu使用率过高问题排查
- SpringSecurity OAuth2在项目中使用完成的功能说明
- linux git还原文件,Gitlab备份到windows、在Linux恢复
- Leetcode--128. 最长连续序列
- java生成随机数的两种方式
- 【跃迁之路】【425天】程序员高效学习方法论探索系列(实验阶段182-2018.04.06)...
- 什么是Java中的原子操作( atomic operations)
- 函数防抖debounce和节流throttle
- wxpython隐藏panel_在wxPython中绘制到Frame内部的Panel
- 数据挖掘工具weka之weka包的安装
- 定时任务最简单的3种实现方法(超好用)
- 尚医通(二十四)微信退款(取消预约功能)
- Arduino/stm32 智能小车设计(二)
- MicroNet论文复现:用极低的FLOPs改进图像识别
- (27)第四节课:从零起步在框架中编码实现损失度Loss的计算及其可视化