1.源码实现
#include <iostream>
#include <elson/Elson.hpp>
using namespace JSON;
using namespace std;
int main()
{
Value val;
Value eval;
Parser p;
val["Name"] = "Homer";
val["Family"]["Wife"] = "Marge";
val["Family"]["Kids"] = { "Bart", "Lisa", "Maggie" };
val["Age"] = 40;
PrettyPrinter printer;
string str = printer.print(val);
cout << str << endl;
p.parse(eval, str);
int answer = val["Age"].as<int>();
cout << answer << endl;
return 0;
}
2.编译源码
$ g++ -o test test.cpp -std=c++11
3.运行及其结果
$ ./test
{
"Age": 40,
"Family": {
"Kids": ["Bart", "Lisa", "Maggie"],
"Wife": "Marge"
},
"Name": "Homer"
}
40
网友评论