文件名称:A JSON parser in C++
文件大小:17KB
文件格式:ZIP
更新时间:2019-10-31 05:17:18
源码,c++
JSON++
Build Status
Introduction
JSON++ is a light-weight JSON parser, writer and reader written in C++. JSON++ can also convert JSON documents into lossless XML documents.
Contributors
http://github.com/hjiang
http://github.com/elanthis
http://github.com/r-lyeh
If 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:
Efficient in both memory and speed.
No third party dependencies. JSON++ only depends on the standard C++ library.
Cross platform.
Robust.
Small and convenient API. Most of the time, you only need to call one function and two function templates.
Easy to integrate. JSON++ only has one source file and one header file. Just compile the source file and link with your program.
Able to construct documents dynamically.
JSON writer: write documents in JSON format.
Other contributors have sinced added more functionalities:
XML writer: convert documents to JSONx format. See http://goo.gl/I3cxs for details.
XML writer: convert documents to JXML format. See https://github.com/r-lyeh/JXML for details.
XML writer: convert documents to JXMLex format. See https://github.com/r-lyeh/JXMLex for details.
XML writer: convert documents to tagged XML format. See https://github.com/hjiang/jsonxx/issues/12 for details.
Compiler version
You need a modern C++ compiler. For older compilers, please try legacy branch.
Configuration
Strict/permissive parsing
JSONxx can parse JSON documents both in strict or permissive mode.
When jsonxx::Settings::Parser is set to Strict, JSONxx parser will accept:
Fully conformant JSON documents only.
When jsonxx::Settings::Parser is set to Permissive, JSONxx parser will accept:
Fully conformant JSON documents
Ending commas in arrays and objects: { "array": [0,1,2,], }
Single quoted strings: ['hello', "world"]
C++ style comments: { "width": 320, "height": 240 } //Picture details
Default value is Permissive.
When jsonxx::Settings::UnquotedKeys is set to Enabled, JSONxx parser will accept:
Unquoted keys: {name: "world"}
Default value is Disabled.
Assertions
JSONxx uses internally JSONXX_ASSERT(...) macro that works both in debug and release mode. Set jsonxx::Settings::Assertions value to Disabled to disable assertions.
Default value is Enabled.
Usage
The 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
【文件预览】:
jsonxx-master
----.travis.yml(44B)
----jsonxx.cc(31KB)
----LICENSE(1KB)
----jsonxx.h(12KB)
----jsonxx_test.cc(19KB)
----.gitignore(37B)
----Makefile(176B)
----README.md(4KB)