diff options
Diffstat (limited to 'doc/tutorial.md')
-rw-r--r-- | doc/tutorial.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md index 0da07dc5..cb76b4b0 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -133,6 +133,15 @@ And other familiar query functions: * `SizeType Capacity() const` * `bool Empty() const` +### Range-based For Loop (New in v1.1.0) + +When C++11 is enabled, you can use range-based for loop to access all elements in an array. + +~~~~~~~~~~cpp +for (auto& v : a.GetArray()) + printf("%d ", v.GetInt()); +~~~~~~~~~~ + ## Query Object {#QueryObject} Similar to array, we can access all object members by iterator: @@ -169,6 +178,16 @@ if (itr != document.MemberEnd()) printf("%s\n", itr->value.GetString()); ~~~~~~~~~~ +### Range-based For Loop (New in v1.1.0) + +When C++11 is enabled, you can use range-based for loop to access all members in an object. + +~~~~~~~~~~cpp +for (auto& m : document.GetObject()) + printf("Type of member %s is %s\n", + m.name.GetString(), kTypeNames[m.value.GetType()]); +~~~~~~~~~~ + ## Querying Number {#QueryNumber} JSON provide a single numerical type called Number. Number can be integer or real numbers. RFC 4627 says the range of Number is specified by parser. |