Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
Json::Reader Class Reference

Unserialize a JSON document into a Value. More...

#include <json.h>

Classes

class  ErrorInfo
 
struct  StructuredError
 An error tagged with where in the JSON text it was encountered. More...
 
class  Token
 

Public Types

typedef char Char
 

Public Member Functions

std::string getFormatedErrorMessages () const
 Returns a user friendly string that list errors in the parsed document. More...
 
std::string getFormattedErrorMessages () const
 Returns a user friendly string that list errors in the parsed document. More...
 
std::vector< StructuredErrorgetStructuredErrors () const
 Returns a vector of structured erros encounted while parsing. More...
 
bool good () const
 Return whether there are any errors. More...
 
bool parse (const char *beginDoc, const char *endDoc, Value &root, bool collectComments=true)
 Read a Value from a JSON document. More...
 
bool parse (const std::string &document, Value &root, bool collectComments=true)
 Read a Value from a JSON document. More...
 
bool parse (std::istream &is, Value &root, bool collectComments=true)
 Parse from input stream. More...
 
bool pushError (const Value &value, const std::string &message)
 Add a semantic error message. More...
 
bool pushError (const Value &value, const std::string &message, const Value &extra)
 Add a semantic error message with extra context. More...
 
 Reader ()
 Constructs a Reader allowing all features for parsing. More...
 
 Reader (const Features &features)
 Constructs a Reader allowing the specified feature set for parsing. More...
 

Public Attributes

const typedef CharLocation
 

Private Types

typedef std::deque< ErrorInfoErrors
 
typedef std::stack< Value * > Nodes
 
enum  TokenType {
  tokenEndOfStream = 0, tokenObjectBegin, tokenObjectEnd, tokenArrayBegin,
  tokenArrayEnd, tokenString, tokenNumber, tokenTrue,
  tokenFalse, tokenNull, tokenArraySeparator, tokenMemberSeparator,
  tokenComment, tokenError
}
 

Private Member Functions

void addComment (Location begin, Location end, CommentPlacement placement)
 
bool addError (const std::string &message, Token &token, Location extra=0)
 
bool addErrorAndRecover (const std::string &message, Token &token, TokenType skipUntilToken)
 
ValuecurrentValue ()
 
bool decodeDouble (Token &token)
 
bool decodeDouble (Token &token, Value &decoded)
 
bool decodeNumber (Token &token)
 
bool decodeNumber (Token &token, Value &decoded)
 
bool decodeString (Token &token)
 
bool decodeString (Token &token, std::string &decoded)
 
bool decodeUnicodeCodePoint (Token &token, Location &current, Location end, unsigned int &unicode)
 
bool decodeUnicodeEscapeSequence (Token &token, Location &current, Location end, unsigned int &unicode)
 
std::string getLocationLineAndColumn (Location location) const
 
void getLocationLineAndColumn (Location location, int &line, int &column) const
 
Char getNextChar ()
 
bool match (Location pattern, int patternLength)
 
bool readArray (Token &token)
 
bool readComment ()
 
bool readCppStyleComment ()
 
bool readCStyleComment ()
 
void readNumber ()
 
bool readObject (Token &token)
 
bool readString ()
 
bool readToken (Token &token)
 
bool readValue ()
 
bool recoverFromError (TokenType skipUntilToken)
 
void skipCommentTokens (Token &token)
 
void skipSpaces ()
 
void skipUntilSpace ()
 

Private Attributes

Location begin_
 
bool collectComments_
 
std::string commentsBefore_
 
Location current_
 
std::string document_
 
Location end_
 
Errors errors_
 
Features features_
 
ValuelastValue_
 
Location lastValueEnd_
 
Nodes nodes_
 

Detailed Description

Unserialize a JSON document into a Value.

Deprecated:
Use CharReader and CharReaderBuilder.

Definition at line 1281 of file json.h.

Member Typedef Documentation

◆ Char

typedef char Json::Reader::Char

Definition at line 1283 of file json.h.

◆ Errors

typedef std::deque<ErrorInfo> Json::Reader::Errors
private

Definition at line 1438 of file json.h.

◆ Nodes

typedef std::stack<Value*> Json::Reader::Nodes
private

Definition at line 1479 of file json.h.

Member Enumeration Documentation

◆ TokenType

Enumerator
tokenEndOfStream 
tokenObjectBegin 
tokenObjectEnd 
tokenArrayBegin 
tokenArrayEnd 
tokenString 
tokenNumber 
tokenTrue 
tokenFalse 
tokenNull 
tokenArraySeparator 
tokenMemberSeparator 
tokenComment 
tokenError 

Definition at line 1407 of file json.h.

Constructor & Destructor Documentation

◆ Reader() [1/2]

Json::Reader::Reader ( )

Constructs a Reader allowing all features for parsing.

Definition at line 274 of file jsoncpp.cpp.

◆ Reader() [2/2]

Json::Reader::Reader ( const Features features)

Constructs a Reader allowing the specified feature set for parsing.

Definition at line 279 of file jsoncpp.cpp.

Member Function Documentation

◆ addComment()

void Json::Reader::addComment ( Location  begin,
Location  end,
CommentPlacement  placement 
)
private

Definition at line 576 of file jsoncpp.cpp.

◆ addError()

bool Json::Reader::addError ( const std::string message,
Token token,
Location  extra = 0 
)
private

Definition at line 936 of file jsoncpp.cpp.

◆ addErrorAndRecover()

bool Json::Reader::addErrorAndRecover ( const std::string message,
Token token,
TokenType  skipUntilToken 
)
private

Definition at line 958 of file jsoncpp.cpp.

◆ currentValue()

Value & Json::Reader::currentValue ( )
private

Definition at line 965 of file jsoncpp.cpp.

◆ decodeDouble() [1/2]

bool Json::Reader::decodeDouble ( Token token)
private

Definition at line 792 of file jsoncpp.cpp.

◆ decodeDouble() [2/2]

bool Json::Reader::decodeDouble ( Token token,
Value decoded 
)
private

Definition at line 802 of file jsoncpp.cpp.

◆ decodeNumber() [1/2]

bool Json::Reader::decodeNumber ( Token token)
private

Definition at line 740 of file jsoncpp.cpp.

◆ decodeNumber() [2/2]

bool Json::Reader::decodeNumber ( Token token,
Value decoded 
)
private

Definition at line 750 of file jsoncpp.cpp.

◆ decodeString() [1/2]

bool Json::Reader::decodeString ( Token token)
private

Definition at line 814 of file jsoncpp.cpp.

◆ decodeString() [2/2]

bool Json::Reader::decodeString ( Token token,
std::string decoded 
)
private

Definition at line 825 of file jsoncpp.cpp.

◆ decodeUnicodeCodePoint()

bool Json::Reader::decodeUnicodeCodePoint ( Token token,
Location current,
Location  end,
unsigned int &  unicode 
)
private

Definition at line 878 of file jsoncpp.cpp.

◆ decodeUnicodeEscapeSequence()

bool Json::Reader::decodeUnicodeEscapeSequence ( Token token,
Location current,
Location  end,
unsigned int &  unicode 
)
private

Definition at line 907 of file jsoncpp.cpp.

◆ getFormatedErrorMessages()

std::string Json::Reader::getFormatedErrorMessages ( ) const

Returns a user friendly string that list errors in the parsed document.

Returns
Formatted error message with the list of errors with their location in the parsed document. An empty string is returned if no error occurred during parsing.
Deprecated:
Use getFormattedErrorMessages() instead (typo fix).

Definition at line 1005 of file jsoncpp.cpp.

◆ getFormattedErrorMessages()

std::string Json::Reader::getFormattedErrorMessages ( ) const

Returns a user friendly string that list errors in the parsed document.

Returns
Formatted error message with the list of errors with their location in the parsed document. An empty string is returned if no error occurred during parsing.

Definition at line 1009 of file jsoncpp.cpp.

◆ getLocationLineAndColumn() [1/2]

std::string Json::Reader::getLocationLineAndColumn ( Location  location) const
private

Definition at line 996 of file jsoncpp.cpp.

◆ getLocationLineAndColumn() [2/2]

void Json::Reader::getLocationLineAndColumn ( Location  location,
int &  line,
int &  column 
) const
private

Definition at line 973 of file jsoncpp.cpp.

◆ getNextChar()

Reader::Char Json::Reader::getNextChar ( )
private

Definition at line 967 of file jsoncpp.cpp.

◆ getStructuredErrors()

std::vector< Reader::StructuredError > Json::Reader::getStructuredErrors ( ) const

Returns a vector of structured erros encounted while parsing.

Returns
A (possibly empty) vector of StructuredError objects. Currently only one error can be returned, but the caller should tolerate multiple errors. This can occur if the parser recovers from a non-fatal parse error and then encounters additional errors.

Definition at line 1025 of file jsoncpp.cpp.

◆ good()

bool Json::Reader::good ( ) const

Return whether there are any errors.

Returns
true if there are no errors to report false if errors have occurred.

Definition at line 1075 of file jsoncpp.cpp.

◆ match()

bool Json::Reader::match ( Location  pattern,
int  patternLength 
)
private

Definition at line 522 of file jsoncpp.cpp.

◆ parse() [1/3]

bool Json::Reader::parse ( const char *  beginDoc,
const char *  endDoc,
Value root,
bool  collectComments = true 
)

Read a Value from a JSON document.

Parameters
beginDocPointer on the beginning of the UTF-8 encoded string of the document to read.
endDocPointer on the end of the UTF-8 encoded string of the document to read. Must be >= beginDoc.
root[out] Contains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
Returns
true if the document was successfully parsed, false if an error occurred.

Definition at line 305 of file jsoncpp.cpp.

◆ parse() [2/3]

bool Json::Reader::parse ( const std::string document,
Value root,
bool  collectComments = true 
)

Read a Value from a JSON document.

Parameters
documentUTF-8 encoded string containing the document to read.
root[out] Contains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
Returns
true if the document was successfully parsed, false if an error occurred.

Definition at line 285 of file jsoncpp.cpp.

◆ parse() [3/3]

bool Json::Reader::parse ( std::istream &  is,
Value root,
bool  collectComments = true 
)

Parse from input stream.

See also
Json::operator>>(std::istream&, Json::Value&).

Definition at line 292 of file jsoncpp.cpp.

◆ pushError() [1/2]

bool Json::Reader::pushError ( const Value value,
const std::string message 
)

Add a semantic error message.

Parameters
valueJSON Value location associated with the error
messageThe error message.
Returns
true if the error was successfully added, false if the Value offset exceeds the document size.

Definition at line 1040 of file jsoncpp.cpp.

◆ pushError() [2/2]

bool Json::Reader::pushError ( const Value value,
const std::string message,
const Value extra 
)

Add a semantic error message with extra context.

Parameters
valueJSON Value location associated with the error
messageThe error message.
extraAdditional JSON Value location to contextualize the error
Returns
true if the error was successfully added, false if either Value offset exceeds the document size.

Definition at line 1057 of file jsoncpp.cpp.

◆ readArray()

bool Json::Reader::readArray ( Token token)
private

Definition at line 702 of file jsoncpp.cpp.

◆ readComment()

bool Json::Reader::readComment ( )
private

Definition at line 533 of file jsoncpp.cpp.

◆ readCppStyleComment()

bool Json::Reader::readCppStyleComment ( )
private

Definition at line 596 of file jsoncpp.cpp.

◆ readCStyleComment()

bool Json::Reader::readCStyleComment ( )
private

Definition at line 587 of file jsoncpp.cpp.

◆ readNumber()

void Json::Reader::readNumber ( )
private

Definition at line 612 of file jsoncpp.cpp.

◆ readObject()

bool Json::Reader::readObject ( Token token)
private

Definition at line 646 of file jsoncpp.cpp.

◆ readString()

bool Json::Reader::readString ( )
private

Definition at line 634 of file jsoncpp.cpp.

◆ readToken()

bool Json::Reader::readToken ( Token token)
private

Definition at line 441 of file jsoncpp.cpp.

◆ readValue()

bool Json::Reader::readValue ( )
private

Definition at line 347 of file jsoncpp.cpp.

◆ recoverFromError()

bool Json::Reader::recoverFromError ( TokenType  skipUntilToken)
private

Definition at line 945 of file jsoncpp.cpp.

◆ skipCommentTokens()

void Json::Reader::skipCommentTokens ( Token token)
private

Definition at line 431 of file jsoncpp.cpp.

◆ skipSpaces()

void Json::Reader::skipSpaces ( )
private

Definition at line 512 of file jsoncpp.cpp.

◆ skipUntilSpace()

void Json::Reader::skipUntilSpace ( )
private

Member Data Documentation

◆ begin_

Location Json::Reader::begin_
private

Definition at line 1483 of file json.h.

◆ collectComments_

bool Json::Reader::collectComments_
private

Definition at line 1490 of file json.h.

◆ commentsBefore_

std::string Json::Reader::commentsBefore_
private

Definition at line 1488 of file json.h.

◆ current_

Location Json::Reader::current_
private

Definition at line 1485 of file json.h.

◆ document_

std::string Json::Reader::document_
private

Definition at line 1482 of file json.h.

◆ end_

Location Json::Reader::end_
private

Definition at line 1484 of file json.h.

◆ errors_

Errors Json::Reader::errors_
private

Definition at line 1481 of file json.h.

◆ features_

Features Json::Reader::features_
private

Definition at line 1489 of file json.h.

◆ lastValue_

Value* Json::Reader::lastValue_
private

Definition at line 1487 of file json.h.

◆ lastValueEnd_

Location Json::Reader::lastValueEnd_
private

Definition at line 1486 of file json.h.

◆ Location

const typedef Char* Json::Reader::Location

Definition at line 1284 of file json.h.

◆ nodes_

Nodes Json::Reader::nodes_
private

Definition at line 1480 of file json.h.


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


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:10