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:
authormiloyip@gmail.com <miloyip@gmail.com@c5894555-1306-4e8d-425f-1f6f381ee07c>2012-11-14 11:07:06 +0400
committermiloyip@gmail.com <miloyip@gmail.com@c5894555-1306-4e8d-425f-1f6f381ee07c>2012-11-14 11:07:06 +0400
commit9b960b6b0af48494bbe1b77becef58851b89e697 (patch)
tree99757825ff594dcdb0ac68ac993ddb11de6faaa0 /example
parent4ee17e67b1a4198f3afa8e2df4624acd5c7aac1f (diff)
Fixed Issue 7: GenericValue& operator[](const Ch* name) - bug if key not found
Makes GenericValue::FindMember() public. Added array element and object member iteration APIs in examples. git-svn-id: https://rapidjson.googlecode.com/svn/trunk@83 c5894555-1306-4e8d-425f-1f6f381ee07c
Diffstat (limited to 'example')
-rw-r--r--example/tutorial/tutorial.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/example/tutorial/tutorial.cpp b/example/tutorial/tutorial.cpp
index 60bac7d0..1b5cacb4 100644
--- a/example/tutorial/tutorial.cpp
+++ b/example/tutorial/tutorial.cpp
@@ -41,6 +41,12 @@ int main(int argc, char* argv[]) {
assert(document["hello"].IsString());
printf("hello = %s\n", document["hello"].GetString());
+ // Since version 0.2, you can use single lookup to check the existing of member and its value:
+ Value::Member* hello = document.FindMember("hello");
+ assert(hello != 0);
+ assert(hello->value.IsString());
+ assert(strcmp("world", hello->value.GetString()) == 0);
+
assert(document["t"].IsBool()); // JSON true/false are bool. Can also uses more specific function IsTrue().
printf("t = %s\n", document["t"].GetBool() ? "true" : "false");
@@ -67,8 +73,20 @@ int main(int argc, char* argv[]) {
//int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type.
int y = a[SizeType(0)].GetInt(); // Cast to SizeType will work.
int z = a[0u].GetInt(); // This works too.
+
+ // Iterating array with iterators
+ printf("a = ");
+ for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
+ printf("%d ", itr->GetInt());
+ printf("\n");
}
+ // Iterating object members
+ static const char* kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" };
+ for (Value::ConstMemberIterator itr = document.MemberBegin(); itr != document.MemberEnd(); ++itr)
+ printf("Type of member %s is %s\n", itr->name.GetString(), kTypeNames[itr->value.GetType()]);
+
+ ////////////////////////////////////////////////////////////////////////////
// 3. Modify values in document.
// Change i to a bigger number