JSON函數表


jsoncpp 主要包含三個class:Value、Reader、Writer。注意Json::Value 只能處理 ANSI 類型的字符串,如果 C++ 程序是用 Unicode 編碼的,最好加一個 Adapt 類來適配。

 

Json內部類和方法:

Reader<是用於讀取的,說的確切點,是用於將字符串轉換為 Json::Value 對象的>

【構造函數】
1、Reader();
【拷貝構造函數】
2、Reader( const Features &features );
【將字符串或者輸入流轉換為JSON的Value對象】
【下邊是相應的parse的重載函數】
3、bool parse( const std::string &document, Value &root,bool collectComments = true );
4、bool parse( const char *beginDoc, const char *endDoc,

Value &root,bool collectComments = true

5、bool parse( std::istream &is,Value &root,bool collectComments = true );
6、std::string getFormatedErrorMessages() const;

Value:<是jsoncpp 中最基本、最重要的類,用於表示各種類型的對象,jsoncpp 支持的對象類型可見 Json::ValueType 枚舉值; Value類的對象代表一個JSON值,既可以代表一個文檔,也可以代表 文檔中一個值。如同JSON中定義的“值”一樣,Value是遞歸的>

【構造函數】
1、Value( ValueType type = nullValue );
Value( Int value );
Value( UInt value );
Value( double value );
Value( const char *value );
Value( const char *beginValue, const char *endValue );
【拷貝構造函數】
2、Value( const StaticString &value );
Value( const std::string &value );
Value( const Value &other );
【相同類型的比較、交換、類型的獲取】
3、void swap( Value &other );
ValueType type() const;
int compare( const Value &other );
【相應的賦值運算符的重載函數】
4、Value &operator=( const Value &other );
bool operator <( const Value &other ) const;
bool operator <=( const Value &other ) const;
bool operator >=( const Value &other ) const;
bool operator >( const Value &other ) const;
bool operator ==( const Value &other ) const;
bool operator !=( const Value &other ) const;
bool operator!() const;
Value &operator[]( UInt index );
const Value &operator[]( UInt index ) const;
【將Value對象進行相應的類型轉換】
5、const char *asCString() const;
std::string asString() const;
const char *asCString() const;
std::string asString() const;
Int asInt() const;
UInt asUInt() const;
double asDouble() const;
【相應的判斷函數】
6、bool isNull() const;
bool isBool() const;
bool isInt() const;
bool isUInt() const;
bool isIntegral() const;
bool isDouble() const;
bool isNumeric() const;
bool isString() const;
bool isArray() const;
bool isObject() const;
bool isConvertibleTo( ValueType other ) const;
bool isValidIndex( UInt index ) const;
bool isMember( const char *key ) const;
bool isMember( const std::string &key ) const;
【清除和擴容函數】
7、void clear();
void resize( UInt size );
【獲取滿足相應條件的Value】
8、Value get( UInt index, const Value &defaultValue ) const;
Value get( const std::string &key,const Value &defaultValue ) const;
Members getMemberNames() const;
【刪除滿足相應條件的Value】
9、Value removeMember( const char* key );
Value removeMember( const std::string &key );
10、void setComment( const char *comment,CommentPlacement placement );
void setComment( const std::string &comment,CommentPlacement placement );
bool hasComment( CommentPlacement placement ) const;
std::string getComment( CommentPlacement placement ) const;
std::string toStyledString()const;

Writer:<類是一個純虛類,並不能直接使用。在此我們使用 Json::Writer 的子類(派生類):
Json::FastWriter、Json::StyledWriter、Json::StyledStreamWriter。顧名思義,用 Json::FastWriter 來處理 json 應該是最快的;負責將內存中的Value對象轉換成JSON文檔,

輸出到文件或者是字符串中>

【FastWriter】
1、FastWriter();
virtual ~FastWriter(){}
void enableYAMLCompatibility();
virtual std::string write( const Value &root );
【StyledWriter】
2、StyledWriter();
virtual ~StyledWriter(){}
virtual std::string write( const Value &root );


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM