diff --git a/Home.md b/Home.md index 10c1183..b8d2bf3 100644 --- a/Home.md +++ b/Home.md @@ -37,19 +37,9 @@ std::ifstream config_doc("config_doc.json", std::ifstream::binary); ``` Once that is done you can then use jsoncpp to parse the data: - ```cpp -Json::Value root; // will contain the root value after parsing -Json::CharReaderBuilder rbuilder; -std::string errs; -bool parsingSuccessful = Json::parseFromStream(rbuilder, config_doc, &root, &errs); -if (!parsingSuccessful) -{ - // report to the user the failure and their locations in the document. - std::cout << "Failed to parse configuration\n" - << errs; - return; -} +Json::Value root; // starts as "null"; will contain the root value after parsing +config_doc >> root; // Get the value of the member of root named 'encoding', return 'UTF-8' if there is no // such member. @@ -71,14 +61,32 @@ root["encoding"] = getCurrentEncoding(); root["indent"]["length"] = getCurrentIndentLength(); root["indent"]["use_space"] = getCurrentIndentUseSpace(); -// Make a new JSON document for the configuration. Preserve original comments. -Json::StreamWriterBuilder wbuilder; -std::string outputConfig = Json::writeString(wbuilder, root); - -// You can also use streams. This will write the contents of a particular JSON -// sub-value, using the default Json::StreamWriterBuilder. -std::cin >> root["subtree"]; +// Make a new JSON document with the new configuration. Preserve original comments. +std::cout << root << "\n"; ``` + +If you need some unusual features, use *Builders*: +```cpp +Json::Value root; +Json::CharReaderBuilder rbuilder; +// Configure the Builder, then ... +std::string errs; +bool parsingSuccessful = Json::parseFromStream(rbuilder, config_doc, &root, &errs); +if (!parsingSuccessful) +{ + // report to the user the failure and their locations in the document. + std::cout << "Failed to parse configuration\n" + << errs; + return; +} + +// ... + +Json::StreamWriterBuilder wbuilder; +// Configure the Builder, then ... +std::string outputConfig = Json::writeString(wbuilder, root); +``` + Build instructions ------------------ The build instructions are located in the file [`README.md`](https://github.com/open-source-parsers/jsoncpp/blob/master/README.md) in the top-directory of the project.