mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-12 10:03:51 +01:00
simplify basic docs
This commit is contained in:
parent
66a8ba255f
commit
6451412c99
@ -71,21 +71,8 @@ root["encoding"] = getCurrentEncoding();
|
||||
root["indent"]["length"] = getCurrentIndentLength();
|
||||
root["indent"]["use_space"] = getCurrentIndentUseSpace();
|
||||
|
||||
// (NEW IN 1.4.0)
|
||||
// To write into a stream with minimal memory overhead,
|
||||
// create a Builder for a StreamWriter.
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder.indentation_ = " "; // or whatever you like
|
||||
|
||||
// Then build a StreamWriter.
|
||||
std::shared_ptr<Json::StreamWriter> writer(
|
||||
builder.newStreamWriter( &std::cout ) );
|
||||
|
||||
// Make a new JSON document for the configuration. Preserve original comments.
|
||||
writer->write( root );
|
||||
|
||||
// If you like the defaults, you can insert directly into a stream.
|
||||
std::cout << root;
|
||||
std::cout << root; // Or see StreamWriterBuilder.
|
||||
|
||||
// If desired, remember to add a linefeed and flush.
|
||||
std::cout << std::endl;
|
||||
@ -94,8 +81,7 @@ std::cout << std::endl;
|
||||
// use `writeString()` for convenience.
|
||||
std::string document = Json::writeString( root, builder );
|
||||
|
||||
// You can also read from a stream. This will put the contents of any JSON
|
||||
// stream at a particular sub-value, if you'd like.
|
||||
// You can also read into a particular sub-value.
|
||||
std::cin >> root["subtree"];
|
||||
\endcode
|
||||
|
||||
|
@ -81,8 +81,7 @@ Usage:
|
||||
Value value = ...;
|
||||
StreamWriterBuilder builder;
|
||||
builder.cs_ = StreamWriter::CommentStyle::None;
|
||||
std::shared_ptr<StreamWriter> writer(
|
||||
builder.newStreamWriter(&std::cout));
|
||||
builder.indentation_ = " "; // or whatever you like
|
||||
writer->write(value);
|
||||
std::cout << std::endl; // add lf and flush
|
||||
\endcode
|
||||
@ -120,7 +119,7 @@ public:
|
||||
* OldCompressingStreamWriterBuilder b;
|
||||
* b.dropNullPlaceHolders_ = true; // etc.
|
||||
* StreamWriter* w = b.newStreamWriter(&std::cout);
|
||||
* w.write(value);
|
||||
* w->write(value);
|
||||
* delete w;
|
||||
* \endcode
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user