系列文章目录
前言
一、环境
Ubuntu18.04
cmake
jsoncpp官方代码:
https://github.com/open-source-parsers/jsoncpp
二、安装
2.1 安装
sudo apt-get install libjsoncpp*
2.2 cmakelist
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
link_libraries(${JSONCPP_LIBRARIES})
message(${JSONCPP_LIBRARIES})
target_link_libraries(<your_target> ${JSONCPP_LIBRARIES})
2.3 包含头文件
#include <jsoncpp/json/json.h>
2.4 头文件路径
/usr/include/jsoncpp
2.5 动态库,静态库路径
/usr/lib/x86_64-linux-gnu/libjsoncpp.so
三、测试是否安装成功
测试代码如下:
#include <jsoncpp/json/json.h>
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
int main()
{
string test ="{\"id\":1,\"name\":\"kurama\"}";
Json::Reader reader;
Json::Value value;
if(reader.parse(test,value))
{
if(!value["id"].isNull())
{
cout<<value["id"].asInt()<<endl;
cout<<value["name"].asString()<<endl;
}
}
return 0;
}
总结
以上就是今天要讲的内容
本文作者:WeSiGJ
参考链接(包括但不限于):
https://blog.csdn.net/pengjian444/article/details/71059860
http://linuxkiss.com/linux/468.html
https://www.jb51.cc/ubuntu/353323.html
https://blog.csdn.net/shyjhyp11/article/details/109893823
https://blog.csdn.net/qq_29796781/article/details/80853300
欢迎各位兄弟姐妹们,加入C++ HTTP服务器开发技术交流群:
QQ群:426685924