$extrastylesheet
JsonCpp project page Classes Namespace JsonCpp home page

Public Member Functions | Static Public Member Functions | Public Attributes
Json::CharReaderBuilder Class Reference

Build a CharReader implementation. More...

#include <json/reader.h>

+ Inheritance diagram for Json::CharReaderBuilder:
+ Collaboration diagram for Json::CharReaderBuilder:

List of all members.

Public Member Functions

 CharReaderBuilder ()
 ~CharReaderBuilder ()
CharReadernewCharReader () const
 Allocate a CharReader via operator new().
bool validate (Json::Value *invalid) const
Valueoperator[] (std::string key)
 A simple way to update a specific setting.

Static Public Member Functions

static void setDefaults (Json::Value *settings)
 Called by ctor, but you can use this to reset settings_.
static void strictMode (Json::Value *settings)
 Same as old Features::strictMode().

Public Attributes

Json::Value settings_
 Configuration of this builder.

Detailed Description

Build a CharReader implementation.

Usage:

  using namespace Json;
  CharReaderBuilder builder;
  builder["collectComments"] = false;
  Value value;
  JSONCPP_STRING errs;
  bool ok = parseFromStream(builder, std::cin, &value, &errs);

Definition at line 298 of file reader.h.


Constructor & Destructor Documentation

Definition at line 1945 of file json_reader.cpp.

References setDefaults(), and settings_.

Definition at line 1949 of file json_reader.cpp.


Member Function Documentation

Allocate a CharReader via operator new().

Exceptions:
std::exceptionif something goes wrong (e.g. invalid settings)

Implements Json::CharReader::Factory.

Definition at line 1951 of file json_reader.cpp.

References Json::Value::asBool(), Json::Value::asInt(), and settings_.

Value & Json::CharReaderBuilder::operator[] ( std::string  key)

A simple way to update a specific setting.

Definition at line 1997 of file json_reader.cpp.

References settings_.

void Json::CharReaderBuilder::setDefaults ( Json::Value settings) [static]

Called by ctor, but you can use this to reset settings_.

Precondition:
'settings' != NULL (but Json::null is fine)
Remarks:
Defaults:
  (*settings)["collectComments"] = true;
  (*settings)["allowComments"] = true;
  (*settings)["strictRoot"] = false;
  (*settings)["allowDroppedNullPlaceholders"] = false;
  (*settings)["allowNumericKeys"] = false;
  (*settings)["allowSingleQuotes"] = false;
  (*settings)["stackLimit"] = 1000;
  (*settings)["failIfExtra"] = false;
  (*settings)["rejectDupKeys"] = false;
  (*settings)["allowSpecialFloats"] = false;

[CharReaderBuilderDefaults]

[CharReaderBuilderDefaults]

Definition at line 2017 of file json_reader.cpp.

Referenced by CharReaderBuilder().

+ Here is the caller graph for this function:

void Json::CharReaderBuilder::strictMode ( Json::Value settings) [static]

Same as old Features::strictMode().

Precondition:
'settings' != NULL (but Json::null is fine)
Remarks:
Defaults:
  (*settings)["allowComments"] = false;
  (*settings)["strictRoot"] = true;
  (*settings)["allowDroppedNullPlaceholders"] = false;
  (*settings)["allowNumericKeys"] = false;
  (*settings)["allowSingleQuotes"] = false;
  (*settings)["stackLimit"] = 1000;
  (*settings)["failIfExtra"] = true;
  (*settings)["rejectDupKeys"] = true;
  (*settings)["allowSpecialFloats"] = false;

[CharReaderBuilderStrictMode]

[CharReaderBuilderStrictMode]

Definition at line 2002 of file json_reader.cpp.

Returns:
true if 'settings' are legal and consistent; otherwise, indicate bad settings via 'invalid'.

Definition at line 1980 of file json_reader.cpp.

References Json::Value::getMemberNames(), Json::getValidReaderKeys(), JSONCPP_STRING, settings_, and Json::Value::size().


Member Data Documentation

Configuration of this builder.

These are case-sensitive. Available settings (case-sensitive):

  • `"collectComments": false or true`
    • true to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if allowComments is false.
  • `"allowComments": false or true`
    • true if comments are allowed.
  • `"strictRoot": false or true`
    • true if root must be either an array or an object value
  • `"allowDroppedNullPlaceholders": false or true`
  • `"allowNumericKeys": false or true`
    • true if numeric object keys are allowed.
  • `"allowSingleQuotes": false or true`
    • true if '' are allowed for strings (both keys and values)
  • `"stackLimit": integer`
    • Exceeding stackLimit (recursive depth of `readValue()`) will cause an exception.
    • This is a security issue (seg-faults caused by deeply nested JSON), so the default is low.
  • `"failIfExtra": false or true`
    • If true, `parse()` returns false when extra non-whitespace trails the JSON value in the input string.
  • `"rejectDupKeys": false or true`
    • If true, `parse()` returns false when a key is duplicated within an object.
  • `"allowSpecialFloats": false or true`
    • If true, special float values (NaNs and infinities) are allowed and their values are lossfree restorable.

You can examine 'settings_` yourself to see the defaults. You can also write and read them just like any JSON Value.

See also:
setDefaults()

Definition at line 338 of file reader.h.

Referenced by CharReaderBuilder(), newCharReader(), operator[](), and validate().


The documentation for this class was generated from the following files: