diff options
author | miloyip <miloyip@gmail.com> | 2014-06-30 05:44:24 +0400 |
---|---|---|
committer | miloyip <miloyip@gmail.com> | 2014-06-30 05:44:24 +0400 |
commit | 389fe87cd8429c7500d5d892d9d196e0cf1aedc8 (patch) | |
tree | 31e567818c90f75e76b1fb811462aeab2c346d45 /example | |
parent | c14c5ff23627c2671799991d65527695c625c7d8 (diff) | |
parent | d8ed60956bb5151f852286bb79849a5383ec3c75 (diff) |
Merge branch 'master' into issue23errorcode
Conflicts:
example/condense/condense.cpp
include/rapidjson/reader.h
test/unittest/readertest.cpp
Diffstat (limited to 'example')
-rw-r--r-- | example/condense/condense.cpp | 2 | ||||
-rw-r--r-- | example/simpledom/simpledom.cpp | 29 | ||||
-rw-r--r-- | example/tutorial/tutorial.cpp | 4 |
3 files changed, 32 insertions, 3 deletions
diff --git a/example/condense/condense.cpp b/example/condense/condense.cpp index ae6d36ac..bad3c91f 100644 --- a/example/condense/condense.cpp +++ b/example/condense/condense.cpp @@ -23,7 +23,7 @@ int main(int, char*[]) { Writer<FileWriteStream> writer(os);
// JSON reader parse from the input stream and let writer generate the output.
- if (!reader.Parse<0>(is, writer)) {
+ if (!reader.Parse(is, writer)) {
fprintf(stderr, "\nError(%u): %s\n", (unsigned)reader.GetErrorOffset(), GetParseError_En(reader.GetParseErrorCode()));
return 1;
}
diff --git a/example/simpledom/simpledom.cpp b/example/simpledom/simpledom.cpp new file mode 100644 index 00000000..a2c9121f --- /dev/null +++ b/example/simpledom/simpledom.cpp @@ -0,0 +1,29 @@ +// 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(json); + + // 2. Modify it by DOM. + Value& s = d["stars"]; + s.SetInt(s.GetInt() + 1); + + // 3. Stringify the DOM + StringBuffer buffer; + Writer<StringBuffer> writer(buffer); + d.Accept(writer); + + // Output {"project":"rapidjson","stars":11} + std::cout << buffer.GetString() << std::endl; + return 0; +} diff --git a/example/tutorial/tutorial.cpp b/example/tutorial/tutorial.cpp index a765e017..592543ea 100644 --- a/example/tutorial/tutorial.cpp +++ b/example/tutorial/tutorial.cpp @@ -19,14 +19,14 @@ int main(int, char*[]) { #if 0
// "normal" parsing, decode strings to new buffers. Can use other input stream via ParseStream().
- if (document.Parse<0>(json).HasParseError())
+ if (document.Parse(json).HasParseError())
return 1;
#else
// In-situ parsing, decode strings directly in the source string. Source must be string.
{
char buffer[sizeof(json)];
memcpy(buffer, json, sizeof(json));
- if (document.ParseInsitu<0>(buffer).HasParseError())
+ if (document.ParseInsitu(buffer).HasParseError())
return 1;
}
#endif
|