PySide6.QtCore.QJsonArray¶
- class QJsonArray¶
- The - QJsonArrayclass encapsulates a JSON array. More…- Synopsis¶- Methods¶- def - __init__()
- def - append()
- def - at()
- def - contains()
- def - count()
- def - empty()
- def - first()
- def - insert()
- def - isEmpty()
- def - last()
- def - __ne__()
- def - __add__()
- def - __iadd__()
- def - __lshift__()
- def - __eq__()
- def - operator[]()
- def - pop_back()
- def - pop_front()
- def - prepend()
- def - push_back()
- def - push_front()
- def - removeAt()
- def - removeFirst()
- def - removeLast()
- def - replace()
- def - size()
- def - swap()
- def - takeAt()
- def - toVariantList()
 - Static functions¶- def - fromStringList()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- A JSON array is a list of values. The list can be manipulated by inserting and removing - QJsonValue‘s from the array.- A - QJsonArraycan be converted to and from a QVariantList . You can query the number of entries with- size(),- insert(), and- removeAt()entries from it and iterate over its content using the standard C++ iterator pattern.- QJsonArrayis 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.- See also - JSON Support in Qt Saving and Loading a Game - __init__()¶
 - Creates an empty array. - __init__(other)
- Parameters:
- other – - QJsonArray
 
 - Creates a copy of - other.- Since - QJsonArrayis implicitly shared, the copy is shallow as long as the object doesn’t get modified.- append(value)¶
- Parameters:
- value – - QJsonValue
 
 - Inserts - valueat the end of the array.- at(i)¶
- Parameters:
- i – int 
- Return type:
 
 - Returns a - QJsonValuerepresenting the value for index- i.- The returned - QJsonValueis- Undefined, if- iis out of bounds.- contains(element)¶
- Parameters:
- element – - QJsonValue
- Return type:
- bool 
 
 - Returns - trueif the array contains an occurrence of- value, otherwise- false.- See also - count()¶
- Return type:
- int 
 
 - Same as - size().- See also - empty()¶
- Return type:
- bool 
 
 - This function is provided for STL compatibility. It is equivalent to - isEmpty()and returns- trueif the array is empty.- first()¶
- Return type:
 
 - Returns the first value stored in the array. - Same as - at(0).- See also - static fromStringList(list)¶
- Parameters:
- list – list of strings 
- Return type:
 
 - Converts the string list - listto a- QJsonArray.- The values in - listwill be converted to JSON values.- See also - static fromVariantList(list)¶
- Parameters:
- list – .list of QVariant 
- Return type:
 
 - Converts the variant list - listto a- QJsonArray.- The - QVariantvalues in- listwill be converted to JSON values.- Note - Conversion from - QVariantis not completely lossless. Please see the documentation in- fromVariant()for more information.- See also - insert(i, value)¶
- Parameters:
- i – int 
- value – - QJsonValue
 
 
 - Inserts - valueat index position- iin the array. If- iis- 0, the value is prepended to the array. If- iis- size(), the value is appended to the array.- See also - isEmpty()¶
- Return type:
- bool 
 
 - Returns - trueif the object is empty. This is the same as- size()== 0.- See also - last()¶
- Return type:
 
 - Returns the last value stored in the array. - Same as - at(size() - 1).- See also - __ne__(rhs)¶
- Parameters:
- rhs – - QJsonArray
- Return type:
- bool 
 
 - Returns - trueif- lhsarray is not equal to- rhs,- falseotherwise.- __ne__(rhs)
- Parameters:
- rhs – - QJsonValue
- Return type:
- bool 
 
 - __add__(v)¶
- Parameters:
- v – - QJsonValue
- Return type:
 
 - Returns an array that contains all the items in this array followed by the provided - value.- See also - operator+=()- __iadd__(v)¶
- Parameters:
- v – - QJsonValue
- Return type:
 
 - Appends - valueto the array, and returns a reference to the array itself.- See also - append()- operator- __lshift__(v)¶
- Parameters:
- v – - QJsonValue
- Return type:
 
 - Appends - valueto the array, and returns a reference to the array itself.- See also - operator+=()- append()- __eq__(rhs)¶
- Parameters:
- rhs – - QJsonArray
- Return type:
- bool 
 
 - Returns - trueif- lhsarray is equal to- rhs,- falseotherwise.- __eq__(rhs)
- Parameters:
- rhs – - QJsonValue
- Return type:
- bool 
 
 - operator(i)¶
- Parameters:
- i – int 
- Return type:
 
 - This is an overloaded function. - Same as - at().- pop_back()¶
 - This function is provided for STL compatibility. It is equivalent to - removeLast(). The array must not be empty. If the array can be empty, call- isEmpty()before calling this function.- pop_front()¶
 - This function is provided for STL compatibility. It is equivalent to - removeFirst(). The array must not be empty. If the array can be empty, call- isEmpty()before calling this function.- prepend(value)¶
- Parameters:
- value – - QJsonValue
 
 - Inserts - valueat the beginning of the array.- This is the same as - insert(0, value)and will prepend- valueto the array.- push_back(t)¶
- Parameters:
- t – - QJsonValue
 
 - This function is provided for STL compatibility. It is equivalent to - append(value)and will append- valueto the array.- push_front(t)¶
- Parameters:
- t – - QJsonValue
 
 - This function is provided for STL compatibility. It is equivalent to - prepend(value)and will prepend- valueto the array.- removeAt(i)¶
- Parameters:
- i – int 
 
 - Removes the value at index position - i.- imust be a valid index position in the array (i.e.,- 0 <= i < size()).- 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.- See also - 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.- See also - replace(i, value)¶
- Parameters:
- i – int 
- value – - QJsonValue
 
 
 - Replaces the item at index position - iwith- value.- imust be a valid index position in the array (i.e.,- 0 <= i < size()).- See also - operator[]()- removeAt()- size()¶
- Return type:
- int 
 
 - Returns the number of values stored in the array. - swap(other)¶
- Parameters:
- other – - QJsonArray
 
 - Swaps this array with - other. This operation is very fast and never fails.- takeAt(i)¶
- Parameters:
- i – int 
- Return type:
 
 - Removes the item at index position - iand returns it.- imust be a valid index position in the array (i.e.,- 0 <= i < size()).- If you don’t use the return value, - removeAt()is more efficient.- See also - toVariantList()¶
- Return type:
- .list of QVariant 
 
 - Converts this object to a QVariantList . - Returns the created map.