mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-05-19 19:56:53 +02:00
deprecate old Reader; separate Advanced Usage section
This commit is contained in:
parent
16bdfd8af3
commit
8df98f6112
@ -51,7 +51,7 @@ preserved.
|
|||||||
|
|
||||||
\code
|
\code
|
||||||
Json::Value root; // 'root' will contain the root value after parsing.
|
Json::Value root; // 'root' will contain the root value after parsing.
|
||||||
std::cin >> root; // Or see CharReaderBuilder.
|
std::cin >> root; // Or see Json::CharReaderBuilder.
|
||||||
|
|
||||||
// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
|
// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
|
||||||
// such member.
|
// such member.
|
||||||
@ -72,17 +72,30 @@ root["indent"]["length"] = getCurrentIndentLength();
|
|||||||
root["indent"]["use_space"] = getCurrentIndentUseSpace();
|
root["indent"]["use_space"] = getCurrentIndentUseSpace();
|
||||||
|
|
||||||
// If you like the defaults, you can insert directly into a stream.
|
// If you like the defaults, you can insert directly into a stream.
|
||||||
std::cout << root; // Or see StreamWriterBuilder.
|
std::cout << root; // Or see Json::StreamWriterBuilder
|
||||||
|
|
||||||
// If desired, remember to add a linefeed and flush.
|
// If desired, remember to add a linefeed and flush.
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
\section _advanced Advanced usage
|
||||||
|
|
||||||
|
\code
|
||||||
// Of course, you can write to `std::ostringstream` if you prefer. Or
|
// Of course, you can write to `std::ostringstream` if you prefer. Or
|
||||||
// use `writeString()` for convenience.
|
// use `writeString()` for convenience, with a specialized builder.
|
||||||
std::string document = Json::writeString( root, builder );
|
Json::StreamWriterBuilder wbuilder;
|
||||||
|
builder.indentation_ = "\t";
|
||||||
|
std::string document = Json::writeString(root, wbuilder);
|
||||||
|
|
||||||
// You can also read into a particular sub-value.
|
// You can also read into a particular sub-value.
|
||||||
std::cin >> root["subtree"];
|
std::cin >> root["subtree"];
|
||||||
|
|
||||||
|
// Here we use a specialized Builder, discard comments, and
|
||||||
|
// record errors.
|
||||||
|
Json::CharReaderBuilder rbuilder;
|
||||||
|
rbuilder.collectComments_ = false;
|
||||||
|
std::string errs;
|
||||||
|
Json::parseFromStream(rbuilder, std::cin, &root["subtree"], &errs);
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
\section _pbuild Build instructions
|
\section _pbuild Build instructions
|
||||||
|
@ -28,6 +28,7 @@ namespace Json {
|
|||||||
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
|
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
|
||||||
*Value.
|
*Value.
|
||||||
*
|
*
|
||||||
|
* \deprecated Use CharReader and CharReaderBuilder.
|
||||||
*/
|
*/
|
||||||
class JSON_API Reader {
|
class JSON_API Reader {
|
||||||
public:
|
public:
|
||||||
@ -280,17 +281,23 @@ Usage:
|
|||||||
\code
|
\code
|
||||||
using namespace Json;
|
using namespace Json;
|
||||||
CharReaderBuilder builder;
|
CharReaderBuilder builder;
|
||||||
builder.collectComments_ = true;
|
builder.collectComments_ = false;
|
||||||
std::shared_ptr<CharReader> reader(
|
|
||||||
builder.newCharReader());
|
|
||||||
Value value;
|
Value value;
|
||||||
std::string errs;
|
std::string errs;
|
||||||
bool ok = parseFromStream(std::cin, &value, &errs);
|
bool ok = parseFromStream(builder, std::cin, &value, &errs);
|
||||||
\endcode
|
\endcode
|
||||||
*/
|
*/
|
||||||
class CharReaderBuilder : public CharReader::Factory {
|
class CharReaderBuilder : public CharReader::Factory {
|
||||||
public:
|
public:
|
||||||
|
/** default: true
|
||||||
|
*
|
||||||
|
* It is possible to "allow" comments but still not "collect" them.
|
||||||
|
*/
|
||||||
bool collectComments_;
|
bool collectComments_;
|
||||||
|
/** default: all()
|
||||||
|
*
|
||||||
|
* For historical reasons, Features is a separate structure.
|
||||||
|
*/
|
||||||
Features features_;
|
Features features_;
|
||||||
|
|
||||||
CharReaderBuilder();
|
CharReaderBuilder();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user