代码拉取完成,页面将自动刷新
git clone https://gitee.com/pgzxb/pgjson.git
cd pgjson
mkdir build
cd build
cmake ..
生成
mingw32-make
或make
生成静态库文件链接使用即可。
MinGW64下的全过程
git clone https://gitee.com/pgzxb/pgjson.git
cd pgjson
mkdir build
cd build
cmake .. -G "MinGW Makefiles"
mingw32-make
# 最终在pgjson/build中有libPGJson.a静态库文件
#include <iostream>
#include <PGJson/Document.h>
using namespace pg::base::json;
int main() {
// Only when PGJSON_DEBUG was defined, can assertion be used in PGJson.
// Plenty of assertions are used in PGJson to DEBUG.
// Recommend you define the macro.
const char json[] = "{\n"
" \"From\" : {\"name\" : \"PGZXB\", \"age\" : 19, \"GPA\" : 4.14},\n"
" \"To\" : \"PGJson\",\n"
" \"sites\": [\n"
" { \"name\":\"CSDN\" , \"url\": \"https://blog.csdn.net/PGZXB?spm=1011.2124.3001.5343\" },\n"
" { \"name\":\"Gitee\" , \"url\":\"https://gitee.com/pgzxb\" },\n"
" { \"name\":\"Zhihu\" , \"url\":\"https://www.zhihu.com/people/geek-81-44\" },\n"
" ]\n"
"}\n"; // The Json-String that will be parsed
// Create Document, which can parse from string/file/stream and stringify DOM to file/string/stream
Document document;
document.parseFromString(json); // parse json form string
Node & DOM = document.d(); // get DOM-Root
// add "msg" : "Hello PGJson!" to DOM-Tree-Root-Object
DOM.addMember("msg")->value.setString("Hello PGJson!");
// stringify the json-tree, default : format-open
std::cout << document.stringify() << "\n\n";
// stringify the json-tree, format-close
std::cout << document.stringify(false) << "\n\n";
return 0;
}
# 在pgjson目录下
g++ hello_pgjson.cpp -L build -lPGJson -o hello_pgjson -I include -DPGJSON_DEBUG -Wall
{
"From" : {
"name" : "PGZXB",
"age" : 19,
"GPA" : 4.140000
},
"To" : "PGJson",
"sites" : [
{
"name" : "CSDN",
"url" : "https://blog.csdn.net/PGZXB?spm=1011.2124.3001.5343"
},
{
"name" : "Gitee",
"url" : "https://gitee.com/pgzxb"
},
{
"name" : "Zhihu",
"url" : "https://www.zhihu.com/people/geek-81-44"
}
],
"msg" : "Hello PGJson!"
}
{"From" : {"name" : "PGZXB","age" : 19,"GPA" : 4.140000},"To" : "PGJson","sites" : [{"name" : "CSDN","url" : "https://blog.csdn.net/PGZXB?spm=1011.2124.
3001.5343"},{"name" : "Gitee","url" : "https://gitee.com/pgzxb"},{"name" : "Zhihu","url" : "https://www.zhihu.com/people/geek-81-44"}],"msg" : "Hello PG
Json!"}
//
,
,
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。