jsoncpp安裝
jsoncpp
是乙個
c++封裝的
json
包,跨平台支援
windows
、linux
、unix
等多系統。
linux
下面編譯需要使用到
cmake
進行編譯。
jsoncpp原始碼
git clone
進到目錄
cd jsoncpp-master
建立目錄
mkdir -p build/release
進到編譯目錄
cd build/release
使用 cmake
進行編譯
cmake -dcmake_build_type=release -dbuild_static_libs=on -
dbuild_shared_libs=off -dcmake_install_includedir=include/jsoncpp -
darchive_install_dir=. -g "unix makefiles" ../..
編譯和安裝
make
sudo make install
檔案引用
#include示例1 簡單的構造乙個json
#include #include #include int main()
,,]}";
json::reader reader;
json::value value;
if (reader.parse(strvalue, value)) }
}void writejson()
int main(int argc, char** ar**)
jsoncpp的使用方法和效能
/*
* @descripttion: 測試jsoncpp的使用方法和效能
* @version: 1.0
* @author: milo
* @date: 2020-06-05 15:14:40
* @lasteditors: milo
* @lastedittime: 2020-06-05 15:14:40
*/#include #include #include #include #include #include #include #include "jsoncpp/json/json.h"
#include "jsoncpp/json/value.h"
#include "jsoncpp/json/reader.h"
#include "jsoncpp/json/writer.h"/*,
"books":[,],
"vip":true,
"address": null
} */
static uint64_t getnowtime()
std::string jsoncppencodenew()
std::string jsoncppencodeold()
// 不能返回引用
json::value jsoncppencodeoldget()
void printjsoncpp(json::value &root)
std::cout << "name: " << root["name"].asstring() << std::endl;
std::cout << "age: " << root["age"].asint() << std::endl;
json::value &languages = root["languages"];
std::cout << "languages: ";
for (uint32_t i = 0; i < languages.size(); ++i)
std::cout << languages[i].asstring();
}std::cout << std::endl;
json::value &phone = root["phone"];
std::cout << "phone number: " << phone["number"].asstring() << ", type: " << phone["type"].asstring() << std::endl;
json::value &books = root["books"];
for (uint32_t i = 0; i < books.size(); ++i)
std::cout << "vip: " << root["vip"].asbool() << std::endl;
if (!root["address"].isnull())
else
}bool jsoncppdecodenew(const std::string &info)
// printjsoncpp(root);
return true;
}bool jsoncppdecodeold(const std::string &strjson)
// printjsoncpp(root);
return true;
}const char *strcjson = ", \
\"books\": [, ], \
\"vip\": true, \
\"address\": null \
} \
";#define test_count 100000
int main()
nowtime = getnowtime();
std::cout << "jsoncpp encode " << test_count << " time, need time: "
<< nowtime-starttime << "ms" << std::endl;
starttime = getnowtime();
std::cout << "\njsoncpp encode time testing" << std::endl;
for(int i = 0; i < test_count; i++)
nowtime = getnowtime();
std::cout << "jsoncpp encode " << test_count << " time, need time: "
<< nowtime-starttime << "ms" << std::endl;
starttime = getnowtime();
std::cout << "\njsoncpp decode time testing" << std::endl;
for(int i = 0; i < test_count; i++)
nowtime = getnowtime();
std::cout << "jsoncpp decode " << test_count << " time, need time: "
<< nowtime-starttime << "ms" << std::endl;
starttime = getnowtime();
std::cout << "\njsoncpp decode time testing" << std::endl;
for(int i = 0; i < test_count; i++)
nowtime = getnowtime();
std::cout << "jsoncpp decode " << test_count << " time, need time: "
<< nowtime-starttime << "ms" << std::endl;
#endif
return 0;
}
g++ jsoncpp_demo01.c -o demo01 -ljsoncpp -std=c++11
g++ jsoncpp_demo02.c -o demo02 -ljsoncpp -std=c++11
g++ jsoncpp_speed.cpp -o jsoncpp_speed -ljsoncpp -std=c++11
jsoncpp的安裝與配置
某些專案需要jsoncpp庫,那麼本文將介紹ubuntu下安裝jsoncpp庫具體步驟。安裝jsoncpp前必須安裝scons。3.解壓scons 3.1.2.tar.gz tar zxvf scons 3.1.2.tar.gz 4.安裝scons 5.解壓jsconcpp tar zvxf jso...
JDK1 8安裝 配置 注意事項及示例
安裝示例 新建j a home 變數值為安裝路徑 path配置 安裝成功 j a 8 又稱為 jdk 1.8 是 j a 語言開發的乙個主要版本。oracle 公司於 2014 年 3 月 18 日發布 j a 8 它支援函式式程式設計,新的 j ascript 引擎,新的日期 api,新的stre...
nginx的安裝配置及使用
一.nginx安裝 cent os 7.0 1.nginx所需的依賴環境 yum install gcc c 2 pcre pcre devel安裝 perl compatible regular expressions 是乙個perl庫,包括perl相容的正規表示式。nginx的http模組使用p...