在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:hjiang/jsonxx开源软件地址:https://github.com/hjiang/jsonxx开源编程语言:C++ 99.7%开源软件介绍:JSON++IntroductionJSON++ is a light-weight JSON parser, writer and reader written in C++. JSON++ can also convert JSON documents into lossless XML documents. ContributorsIf you've made substantial contribution, please add your link here. Why another JSON parser?Perhaps because web service clients are usually written in dynamic languages these days, none of the existing C++ JSON parsers fitted my needs very well, so I wrote one that I used in another project. My goals for JSON++ were:
Other contributors have sinced added more functionalities:
Compiler versionYou need a modern C++ compiler. For older compilers, please try legacy branch. ConfigurationStrict/permissive parsingJSONxx can parse JSON documents both in strict or permissive mode. When
When
Default value is When
Default value is AssertionsJSONxx uses internally Default value is UsageThe following snippets are from one of the unit tests. They are quite self-descriptive. using namespace std;
using namespace jsonxx;
string teststr(
"{"
" \"foo\" : 1,"
" \"bar\" : false,"
" \"person\" : {\"name\" : \"GWB\", \"age\" : 60,},"
" \"data\": [\"abcd\", 42],"
"}"
);
// Parse string or stream
Object o;
assert(o.parse(teststr));
// Validation. Checking for JSON types and values as well
assert(1 == o.get<Number>("foo"));
assert(o.has<Boolean>("bar"));
assert(o.has<Object>("person"));
assert(o.get<Object>("person").has<Number>("age"));
assert(!o.get<Object>("person").has<Boolean>("old"));
assert(o.get<Object>("person").get<Boolean>("old", false));
assert(o.has<Array>("data"));
assert(o.get<Array>("data").get<Number>(1) == 42);
assert(o.get<Array>("data").get<String>(0) == "abcd");
assert(o.get<Array>("data").get<String>(2, "hello") == "hello");
assert(!o.has<Number>("data"));
cout << o.json() << endl; // JSON output
cout << o.xml(JSONx) << endl; // JSON to XML conversion (JSONx subtype)
cout << o.xml(JXML) << endl; // JSON to XML conversion (JXML subtype)
cout << o.xml(JXMLex) << endl; // JSON to XML conversion (JXMLex subtype) // Generate JSON document dynamically
using namespace std;
using namespace jsonxx;
Array a;
a << 123;
a << "hello world";
a << 3.1415;
a << 99.95f;
a << 'h';
a << Object("key", "value");
Object o;
o << "key1" << "value";
o << "key2" << 123;
o << "key3" << a;
cout << o.json() << endl; To do
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论