diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/rapidjson/example/simplewriter | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/rapidjson/example/simplewriter/simplewriter.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/rapidjson/example/simplewriter/simplewriter.cpp b/src/rapidjson/example/simplewriter/simplewriter.cpp new file mode 100644 index 000000000..8d1275c29 --- /dev/null +++ b/src/rapidjson/example/simplewriter/simplewriter.cpp @@ -0,0 +1,36 @@ +#include "rapidjson/writer.h" +#include "rapidjson/stringbuffer.h" +#include <iostream> + +using namespace rapidjson; +using namespace std; + +int main() { + StringBuffer s; + Writer<StringBuffer> writer(s); + + writer.StartObject(); // Between StartObject()/EndObject(), + writer.Key("hello"); // output a key, + writer.String("world"); // follow by a value. + writer.Key("t"); + writer.Bool(true); + writer.Key("f"); + writer.Bool(false); + writer.Key("n"); + writer.Null(); + writer.Key("i"); + writer.Uint(123); + writer.Key("pi"); + writer.Double(3.1416); + writer.Key("a"); + writer.StartArray(); // Between StartArray()/EndArray(), + for (unsigned i = 0; i < 4; i++) + writer.Uint(i); // all values are elements of the array. + writer.EndArray(); + writer.EndObject(); + + // {"hello":"world","t":true,"f":false,"n":null,"i":123,"pi":3.1416,"a":[0,1,2,3]} + cout << s.GetString() << endl; + + return 0; +} |