diff options
author | Milo Yip <miloyip@gmail.com> | 2014-06-28 15:44:11 +0400 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2014-06-28 15:44:11 +0400 |
commit | cd144c3cfdc568278700484a4083a7b084d47dee (patch) | |
tree | f9097ebd3d62e5ec92a579af72fc774ea851146b /example | |
parent | b2b12a6367bbaac77f5e54315fb9b8cbb2bee67d (diff) |
Added a simple example and a diagram showing the process.
Diffstat (limited to 'example')
-rw-r--r-- | example/simpledom/simpledom.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/example/simpledom/simpledom.cpp b/example/simpledom/simpledom.cpp new file mode 100644 index 00000000..bdcf6c89 --- /dev/null +++ b/example/simpledom/simpledom.cpp @@ -0,0 +1,28 @@ +// JSON simple example +// This example does not handle errors. + +#include "rapidjson/document.h" +#include "rapidjson/writer.h" +#include "rapidjson/stringbuffer.h" +#include <iostream> + +using namespace rapidjson; + +int main() { + // 1. Parse a JSON string into DOM. + const char* json = "{\"project\":\"rapidjson\",\"stars\":10}"; + Document d; + d.Parse<0>(json); + + // 2. Modify it by DOM. + d["stars"].SetInt(d["stars"].GetInt() + 1); + + // 3. Stringify the DOM + StringBuffer buffer; + Writer<StringBuffer> writer(buffer); + d.Accept(writer); + + // Output {"project":"rapidjson","stars":10} + std::cout << buffer.GetString() << std::endl; + return 0; +} |