QJsonArray 類

The QJsonArray class encapsulates a JSON array. 更多...

頭: #include <QJsonArray>
qmake: QT += core
Since: Qt 5.0

注意: 此類的所有函數 可重入 .

公共類型

class const_iterator
class iterator
typedef ConstIterator
typedef Iterator
typedef const_pointer
typedef const_reference
typedef difference_type
typedef pointer
typedef reference
typedef size_type
typedef value_type

公共函數

QJsonArray ()
QJsonArray (std::initializer_list<QJsonValue> args )
QJsonArray (const QJsonArray & other )
~QJsonArray ()
void append (const QJsonValue & value )
QJsonValue at (int i ) const
iterator begin ()
const_iterator begin () const
const_iterator constBegin () const
const_iterator constEnd () const
bool contains (const QJsonValue & value ) const
int count () const
bool empty () const
iterator end ()
const_iterator end () const
iterator erase (iterator it )
QJsonValue first () const
void insert (int i , const QJsonValue & value )
iterator insert (iterator before , const QJsonValue & value )
bool isEmpty () const
QJsonValue last () const
void pop_back ()
void pop_front ()
void prepend (const QJsonValue & value )
void push_back (const QJsonValue & value )
void push_front (const QJsonValue & value )
void removeAt (int i )
void removeFirst ()
void removeLast ()
void replace (int i , const QJsonValue & value )
int size () const
QJsonValue takeAt (int i )
QVariantList toVariantList () const
bool operator!= (const QJsonArray & other ) const
QJsonArray operator+ (const QJsonValue & value ) const
QJsonArray & operator+= (const QJsonValue & value )
QJsonArray & operator<< (const QJsonValue & value )
QJsonArray & operator= (const QJsonArray & other )
bool operator== (const QJsonArray & other ) const
QJsonValueRef operator[] (int i )
QJsonValue operator[] (int i ) const

靜態公共成員

QJsonArray fromStringList (const QStringList & list )
QJsonArray fromVariantList (const QVariantList & list )

詳細描述

The QJsonArray class encapsulates a JSON array.

A JSON array is a list of values. The list can be manipulated by inserting and removing QJsonValue 's from the array.

A QJsonArray can be converted to and from a QVariantList . You can query the number of entries with size (), insert (),和 removeAt () entries from it and iterate over its content using the standard C++ iterator pattern.

QJsonArray is an implicitly shared class and shares the data with the document it has been created from as long as it is not being modified.

You can convert the array to and from text based JSON through QJsonDocument .

另請參閱 在 Qt 中支持 JSON and JSON 保存遊戲範例 .

成員類型文檔編製

typedef QJsonArray:: ConstIterator

Qt 樣式同義詞 QJsonArray::const_iterator .

typedef QJsonArray:: Iterator

Qt 樣式同義詞 QJsonArray::iterator .

typedef QJsonArray:: const_pointer

Typedef for const QJsonValue *. Provided for STL compatibility.

typedef QJsonArray:: const_reference

Typedef for const QJsonValue &. Provided for STL compatibility.

typedef QJsonArray:: difference_type

typedef 對於 int。為兼容 STL 提供。

typedef QJsonArray:: pointer

typedef 對於 QJsonValue *. Provided for STL compatibility.

typedef QJsonArray:: reference

typedef 對於 QJsonValue &. Provided for STL compatibility.

typedef QJsonArray:: size_type

typedef 對於 int。為兼容 STL 提供。

typedef QJsonArray:: value_type

typedef 對於 QJsonValue . Provided for STL compatibility.

成員函數文檔編製

QJsonArray:: QJsonArray ()

Creates an empty array.

QJsonArray:: QJsonArray ( std::initializer_list < QJsonValue > args )

Creates an array initialized from args initialization list.

QJsonArray can be constructed in a way similar to JSON notation, for example:

QJsonArray array = { 1, 2.2, QString() };
					

該函數在 Qt 5.4 引入。

QJsonArray:: QJsonArray (const QJsonArray & other )

創建副本為 other .

由於 QJsonArray is implicitly shared, the copy is shallow as long as the object doesn't get modified.

QJsonArray:: ~QJsonArray ()

Deletes the array.

void QJsonArray:: append (const QJsonValue & value )

插入 value at the end of the array.

另請參閱 prepend () 和 insert ().

QJsonValue QJsonArray:: at ( int i ) const

返迴 QJsonValue representing the value for index i .

返迴的 QJsonValue is 未定義 ,若 i is out of bounds.

iterator QJsonArray:: begin ()

返迴 STL 樣式迭代器 pointing to the first item in the array.

另請參閱 constBegin () 和 end ().

const_iterator QJsonArray:: begin () const

這是重載函數。

const_iterator QJsonArray:: constBegin () const

返迴常量 STL 樣式迭代器 pointing to the first item in the array.

另請參閱 begin () 和 constEnd ().

const_iterator QJsonArray:: constEnd () const

返迴常量 STL 樣式迭代器 pointing to the imaginary item after the last item in the array.

另請參閱 constBegin () 和 end ().

bool QJsonArray:: contains (const QJsonValue & value ) const

返迴 true if the array contains an occurrence of value , otherwise false .

另請參閱 count ().

int QJsonArray:: count () const

如同 size ().

另請參閱 size ().

bool QJsonArray:: empty () const

此函數為兼容 STL (標準模闆庫) 提供。它相當於 isEmpty () 並返迴 true if the array is empty.

iterator QJsonArray:: end ()

返迴 STL 樣式迭代器 pointing to the imaginary item after the last item in the array.

另請參閱 begin () 和 constEnd ().

const_iterator QJsonArray:: end () const

這是重載函數。

iterator QJsonArray:: erase ( iterator it )

Removes the item pointed to by it , and returns an iterator pointing to the next item.

另請參閱 removeAt ().

QJsonValue QJsonArray:: first () const

Returns the first value stored in the array.

如同 at(0) .

另請參閱 at ().

[static] QJsonArray QJsonArray:: fromStringList (const QStringList & list )

Converts the string list list QJsonArray .

The values in list will be converted to JSON values.

另請參閱 toVariantList () 和 QJsonValue::fromVariant ().

[static] QJsonArray QJsonArray:: fromVariantList (const QVariantList & list )

Converts the variant list list QJsonArray .

The QVariant 值在 list will be converted to JSON values.

另請參閱 toVariantList () 和 QJsonValue::fromVariant ().

void QJsonArray:: insert ( int i , const QJsonValue & value )

插入 value at index position i in the array. If i is 0 , the value is prepended to the array. If i is size (), the value is appended to the array.

另請參閱 append (), prepend (), replace (),和 removeAt ().

iterator QJsonArray:: insert ( iterator before , const QJsonValue & value )

插入 value before the position pointed to by before , and returns an iterator pointing to the newly inserted item.

另請參閱 erase () 和 insert ().

bool QJsonArray:: isEmpty () const

返迴 true if the object is empty. This is the same as size () == 0.

另請參閱 size ().

QJsonValue QJsonArray:: last () const

Returns the last value stored in the array.

如同 at(size() - 1) .

另請參閱 at ().

void QJsonArray:: pop_back ()

此函數為兼容 STL (標準模闆庫) 提供。它相當於 removeLast (). The array must not be empty. If the array can be empty, call isEmpty () before calling this function.

void QJsonArray:: pop_front ()

此函數為兼容 STL (標準模闆庫) 提供。它相當於 removeFirst (). The array must not be empty. If the array can be empty, call isEmpty () before calling this function.

void QJsonArray:: prepend (const QJsonValue & value )

插入 value at the beginning of the array.

這如同 insert(0, value) and will prepend value to the array.

另請參閱 append () 和 insert ().

void QJsonArray:: push_back (const QJsonValue & value )

此函數為兼容 STL (標準模闆庫) 提供。它相當於 append (value) and will append value to the array.

void QJsonArray:: push_front (const QJsonValue & value )

此函數為兼容 STL (標準模闆庫) 提供。它相當於 prepend (value) and will prepend value to the array.

void QJsonArray:: removeAt ( int i )

Removes the value at index position i . i must be a valid index position in the array (i.e., 0 <= i < size() ).

另請參閱 insert () 和 replace ().

void QJsonArray:: removeFirst ()

Removes the first item in the array. Calling this function is equivalent to calling removeAt(0) . The array must not be empty. If the array can be empty, call isEmpty () before calling this function.

另請參閱 removeAt () 和 removeLast ().

void QJsonArray:: removeLast ()

Removes the last item in the array. Calling this function is equivalent to calling removeAt(size() - 1) . The array must not be empty. If the array can be empty, call isEmpty () before calling this function.

另請參閱 removeAt () 和 removeFirst ().

void QJsonArray:: replace ( int i , const QJsonValue & value )

替換項在索引位置 i with value . i must be a valid index position in the array (i.e., 0 <= i < size() ).

另請參閱 operator[] () 和 removeAt ().

int QJsonArray:: size () const

Returns the number of values stored in the array.

QJsonValue QJsonArray:: takeAt ( int i )

Removes the item at index position i 並返迴它。 i must be a valid index position in the array (i.e., 0 <= i < size() ).

若不使用返迴值, removeAt () 效率更高。

另請參閱 removeAt ().

QVariantList QJsonArray:: toVariantList () const

把此對象轉換成 QVariantList .

返迴創建的映射。

bool QJsonArray:: operator!= (const QJsonArray & other ) const

返迴 true if this array is not equal to other .

QJsonArray QJsonArray:: operator+ (const QJsonValue & value ) const

Returns an array that contains all the items in this array followed by the provided value .

該函數在 Qt 5.3 引入。

另請參閱 operator+= ().

QJsonArray &QJsonArray:: operator+= (const QJsonValue & value )

追加 value to the array, and returns a reference to the array itself.

該函數在 Qt 5.3 引入。

另請參閱 append () 和 operator<< ().

QJsonArray &QJsonArray:: operator<< (const QJsonValue & value )

追加 value to the array, and returns a reference to the array itself.

該函數在 Qt 5.3 引入。

另請參閱 operator+= () 和 append ().

QJsonArray &QJsonArray:: operator= (const QJsonArray & other )

賦值 other 到此數組。

bool QJsonArray:: operator== (const QJsonArray & other ) const

返迴 true if this array is equal to other .

QJsonValueRef QJsonArray:: operator[] ( int i )

Returns the value at index position i 作為可修改引用。 i must be a valid index position in the array (i.e., 0 <= i < size() ).

The return value is of type QJsonValueRef , a helper class for QJsonArray and QJsonObject . When you get an object of type QJsonValueRef , you can use it as if it were a reference to a QJsonValue . If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference.

另請參閱 at ().

QJsonValue QJsonArray:: operator[] ( int i ) const

這是重載函數。

如同 at ().