@@ -53,23 +53,26 @@ preserved.
5353Json::Value root; // 'root' will contain the root value after parsing.
5454std::cin >> root;
5555
56+ // You can also read into a particular sub-value.
57+ std::cin >> root["subtree"];
58+
5659// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
5760// such member.
5861std::string encoding = root.get("encoding", "UTF-8" ).asString();
59- // Get the value of the member of root named 'encoding', return a 'null' value if
62+ // Get the value of the member of root named 'encoding'; return a 'null' value if
6063// there is no such member.
6164const Json::Value plugins = root["plug-ins"];
6265for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
6366 loadPlugIn( plugins[index].asString() );
6467
65- setIndentLength( root["indent"].get("length", 3).asInt() );
66- setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
68+ foo:: setIndentLength( root["indent"].get("length", 3).asInt() );
69+ foo:: setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
6770
6871// Since Json::Value has implicit constructor for all value types, it is not
6972// necessary to explicitly construct the Json::Value object:
70- root["encoding"] = getCurrentEncoding();
71- root["indent"]["length"] = getCurrentIndentLength();
72- root["indent"]["use_space"] = getCurrentIndentUseSpace();
73+ root["encoding"] = foo:: getCurrentEncoding();
74+ root["indent"]["length"] = foo:: getCurrentIndentLength();
75+ root["indent"]["use_space"] = foo:: getCurrentIndentUseSpace();
7376
7477// If you like the defaults, you can insert directly into a stream.
7578std::cout << root;
@@ -80,27 +83,24 @@ std::cout << std::endl;
8083\endcode
8184
8285\section _advanced Advanced usage
83- We are finalizing the new *Builder* API, which will be in versions
84- `1.4.0` and `0.8.0` when released. Until then, you may continue to
85- use the old API, include `Writer`, `Reader`, and `Feature`.
86- \code
8786
88- // EXPERIMENTAL
89- // Or use `writeString()` for convenience, with a specialized builder.
90- Json::StreamWriterBuilder wbuilder;
91- builder.indentation_ = "\t";
92- std::string document = Json::writeString(root, wbuilder);
87+ Configure *builders* to create *readers* and *writers*. For
88+ configuration, we use our own `Json::Value` (rather than
89+ standard setters/getters) so that we can add
90+ features without losing binary-compatibility.
9391
94- // You can also read into a particular sub-value.
95- std::cin >> root["subtree"];
92+ \code
93+ // For convenience, use `writeString()` with a specialized builder.
94+ Json::StreamWriterBuilder wbuilder;
95+ wbuilder.settings["indentation"] = "\t";
96+ std::string document = Json::writeString(wbuilder, root);
9697
97- // EXPERIMENTAL
98- // Here we use a specialized Builder, discard comments, and
99- // record errors.
98+ // Here, using a specialized Builder, we discard comments and
99+ // record errors as we parse.
100100Json::CharReaderBuilder rbuilder;
101- rbuilder.collectComments_ = false;
101+ rbuilder.settings["collectComments"] = false;
102102std::string errs;
103- Json::parseFromStream(rbuilder, std::cin, &root["subtree"] , &errs);
103+ bool ok = Json::parseFromStream(rbuilder, std::cin, &root, &errs);
104104\endcode
105105
106106\section _pbuild Build instructions
0 commit comments