Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Yip <miloyip@gmail.com>2014-06-28 15:44:11 +0400
committerMilo Yip <miloyip@gmail.com>2014-06-28 15:44:11 +0400
commitcd144c3cfdc568278700484a4083a7b084d47dee (patch)
treef9097ebd3d62e5ec92a579af72fc774ea851146b /readme.md
parentb2b12a6367bbaac77f5e54315fb9b8cbb2bee67d (diff)
Added a simple example and a diagram showing the process.
Diffstat (limited to 'readme.md')
-rw-r--r--readme.md43
1 files changed, 42 insertions, 1 deletions
diff --git a/readme.md b/readme.md
index 894fb440..18d8b95c 100644
--- a/readme.md
+++ b/readme.md
@@ -41,9 +41,50 @@ Rapidjson is a header-only C++ library. Just copy the `rapidjson/include/rapidjs
To build the tests and examples:
-1. Obtain [premake4] (http://industriousone.com/premake/download).
+1. Obtain [premake4](http://industriousone.com/premake/download).
2. Copy premake4 executable to rapidjson/build (or system path)
3. Run `rapidjson/build/premake.bat` on Windows, `rapidjson/build/premake.sh` on Linux or other platforms
4. On Windows, build the solution at `rapidjson/build/vs2008/` or `/vs2010/`
5. On other platforms, run GNU make at `rapidjson/build/gmake/` (e.g., `make -f test.make config=release32`, `make -f example.make config=debug32`)
6. On success, the executable are generated at `rapidjson/bin`
+
+## Usage at a glance
+
+This simple example parses a JSON string into a document (DOM), make a simple modification of the DOM, and finally stringify the DOM to a JSON string.
+
+```cpp
+// example/simpledom/simpledom.cpp
+#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;
+}
+```
+
+Note that this exmample did not handle potential errors.
+
+The following diagram shows the process.
+
+[simpledom](doc/diagram/simpledom.png)
+
+More [examples](example/) are avaliable.