QJsonArray Class
A classe QJsonArray encapsula um array JSON. Saiba mais...
| Cabeçalho: | #include <QJsonArray> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
- Lista de todos os membros, incluindo os herdados
- QJsonArray faz parte do Suporte a JSON no Qt e das Classes Compartilhadas Implicitamente.
Observação: Todas as funções desta classe são reentrantes.
Comparações do QJsonArray
| Categoria | Tipos comparáveis |
|---|---|
| igualdade | QJsonArray |
| igualdade | QJsonValue. |
Tipos públicos
| class | const_iterator |
| class | iterator |
| ConstIterator | |
| Iterator | |
| const_pointer | |
| const_reference | |
| difference_type | |
| pointer | |
| reference | |
| size_type | |
| value_type |
Funções públicas
| QJsonArray() | |
| QJsonArray(std::initializer_list<QJsonValue> args) | |
| QJsonArray(const QJsonArray &other) | |
| QJsonArray(QJsonArray &&other) | |
| ~QJsonArray() | |
| void | append(const QJsonValue &value) |
| QJsonValue | at(qsizetype i) const |
| QJsonArray::iterator | begin() |
| QJsonArray::const_iterator | begin() const |
| QJsonArray::const_iterator | cbegin() const |
| QJsonArray::const_iterator | cend() const |
| QJsonArray::const_iterator | constBegin() const |
| QJsonArray::const_iterator | constEnd() const |
| bool | contains(const QJsonValue &value) const |
| qsizetype | count() const |
| bool | empty() const |
| QJsonArray::iterator | end() |
| QJsonArray::const_iterator | end() const |
| QJsonArray::iterator | erase(QJsonArray::iterator it) |
| QJsonValue | first() const |
| QJsonArray::iterator | insert(QJsonArray::iterator before, const QJsonValue &value) |
| void | insert(qsizetype i, 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(qsizetype i) |
| void | removeFirst() |
| void | removeLast() |
| void | replace(qsizetype i, const QJsonValue &value) |
| qsizetype | size() const |
| void | swap(QJsonArray &other) |
| QJsonValue | takeAt(qsizetype i) |
| QVariantList | toVariantList() const |
| QJsonArray | operator+(const QJsonValue &value) const |
| QJsonArray & | operator+=(const QJsonValue &value) |
| QJsonArray & | operator<<(const QJsonValue &value) |
| QJsonArray & | operator=(QJsonArray &&other) |
| QJsonArray & | operator=(const QJsonArray &other) |
| QJsonValueRef | operator[](qsizetype i) |
| QJsonValue | operator[](qsizetype i) const |
Membros públicos estáticos
| QJsonArray | fromStringList(const QStringList &list) |
| QJsonArray | fromVariantList(const QVariantList &list) |
Elementos não-membros relacionados
| bool | operator!=(const QJsonArray &lhs, const QJsonArray &rhs) |
| bool | operator==(const QJsonArray &lhs, const QJsonArray &rhs) |
Descrição detalhada
Um array JSON é uma lista de valores. A lista pode ser manipulada inserindo e removendo objetos ` QJsonValue` do array.
Um `QJsonArray` pode ser convertido de e para um ` QVariantList`. É possível consultar o número de entradas com ` size()`, ` insert()` e ` removeAt()`, bem como iterar sobre seu conteúdo usando o padrão de iterador padrão do C++.
QJsonArray é uma classe compartilhada implicitamente e compartilha os dados com o documento a partir do qual foi criada, desde que não esteja sendo modificada.
É possível converter a matriz de e para JSON baseado em texto por meio de QJsonDocument.
Veja também Suporte a JSON no Qt e Salvando e carregando um jogo.
Documentação dos tipos de membros
QJsonArray::ConstIterator
Sinônimo no estilo Qt para “ QJsonArray::const_iterator ”.
QJsonArray::Iterator
Sinônimo no estilo Qt para “ QJsonArray::iterator ”.
QJsonArray::const_pointer
Typedef para const QJsonValue *. Fornecido para compatibilidade com a STL.
QJsonArray::const_reference
Definição de tipo (typedef) para const QJsonValue &. Fornecida para compatibilidade com a STL.
QJsonArray::difference_type
Definrição de tipo para `qsizetype`. Fornecida para compatibilidade com a STL.
QJsonArray::pointer
Definição de tipo para QJsonValue *. Fornecida para compatibilidade com a STL.
QJsonArray::reference
Typedef para ` QJsonValue ` e `&`. Fornecido para compatibilidade com a STL.
QJsonArray::size_type
Definição de tipo para `qsizetype`. Fornecida para compatibilidade com a STL.
QJsonArray::value_type
Definição de tipo para ` QJsonValue`. Fornecida para compatibilidade com a STL.
Documentação das funções-membro
QJsonArray::QJsonArray()
Cria um array vazio.
QJsonArray::QJsonArray(std::initializer_list<QJsonValue> args)
Cria um array inicializado a partir de uma lista de inicialização d args.
O `QJsonArray` pode ser construído de maneira semelhante à notação JSON, por exemplo:
QJsonArray array = { 1, 2.2, QString() };[noexcept] QJsonArray::QJsonArray(const QJsonArray &other)
Cria uma cópia de ` other`.
Como o `QJsonArray` é compartilhado implicitamente, a cópia é superficial, desde que o objeto não seja modificado.
[noexcept] QJsonArray::QJsonArray(QJsonArray &&other)
Cria um QJsonArray a partir de other.
[noexcept] QJsonArray::~QJsonArray()
Exclui a matriz.
void QJsonArray::append(const QJsonValue &value)
Inser value no final da matriz.
Veja também prepend() e insert().
QJsonValue QJsonArray::at(qsizetype i) const
Retorna um objeto ` QJsonValue ` que representa o valor correspondente ao índice ` i`.
O ` QJsonValue ` retornado é ` Undefined`, caso ` i ` esteja fora dos limites.
QJsonArray::iterator QJsonArray::begin()
Retorna um iterador no estilo STL que aponta para o primeiro item da matriz.
Veja também constBegin() e end().
QJsonArray::const_iterator QJsonArray::begin() const
Esta é uma função sobrecarregada.
QJsonArray::const_iterator QJsonArray::cbegin() const
Retorna um iterador constante no estilo STL que aponta para o primeiro item da matriz.
QJsonArray::const_iterator QJsonArray::cend() const
Retorna um iterador constante no estilo STL que aponta para o item imaginário após o último item da matriz.
Veja também ` cbegin()` e ` end()`.
QJsonArray::const_iterator QJsonArray::constBegin() const
Retorna um iterador constante no estilo STL que aponta para o primeiro item da matriz.
Veja também ` begin()` e ` constEnd()`.
QJsonArray::const_iterator QJsonArray::constEnd() const
Retorna um iterador const no estilo STL que aponta para o item imaginário após o último item da matriz.
Veja também constBegin() e end().
bool QJsonArray::contains(const QJsonValue &value) const
Retorna ` true ` se o array contiver uma ocorrência de ` value`; caso contrário, retorna ` false`.
Veja também count().
qsizetype QJsonArray::count() const
É o mesmo que size().
Veja também size().
bool QJsonArray::empty() const
Esta função é fornecida para fins de compatibilidade com a STL. É equivalente a ` isEmpty()` e retorna ` true ` se a matriz estiver vazia.
QJsonArray::iterator QJsonArray::end()
Retorna um iterador no estilo STL que aponta para o item imaginário após o último item da matriz.
Veja também ` begin()` e ` constEnd()`.
QJsonArray::const_iterator QJsonArray::end() const
Esta é uma função sobrecarregada.
QJsonArray::iterator QJsonArray::erase(QJsonArray::iterator it)
Remove o item apontado por ` it` e retorna um iterador que aponta para o próximo item.
Veja também removeAt().
QJsonValue QJsonArray::first() const
Retorna o primeiro valor armazenado na matriz.
Equivalente a ` at(0)`.
Veja também at().
[static] QJsonArray QJsonArray::fromStringList(const QStringList &list)
Converte a lista de strings list em um QJsonArray.
Os valores em list serão convertidos em valores JSON.
Veja também toVariantList() e QJsonValue::fromVariant().
[static] QJsonArray QJsonArray::fromVariantList(const QVariantList &list)
Converte a lista de variantes list em um QJsonArray.
Os valores do tipo “ QVariant ” no “ list ” serão convertidos em valores JSON.
Observação: a conversão de QVariant não é totalmente sem perdas. Consulte a documentação em QJsonValue::fromVariant() para obter mais informações.
Veja também toVariantList() e QJsonValue::fromVariant().
QJsonArray::iterator QJsonArray::insert(QJsonArray::iterator before, const QJsonValue &value)
Inser value antes da posição apontada por before e retorna um iterador que aponta para o item recém-inserido.
Veja também erase() e insert(qsizetype, const QJsonValue &).
void QJsonArray::insert(qsizetype i, const QJsonValue &value)
Inser value na posição de índice i na matriz. Se i for 0, o valor é inserido no início da matriz. Se i for size(), o valor é inserido no final da matriz.
Veja também append(), prepend(), replace() e removeAt().
bool QJsonArray::isEmpty() const
Retorna true se o objeto estiver vazio. Isso equivale a size() == 0.
Veja também size().
QJsonValue QJsonArray::last() const
Retorna o último valor armazenado na matriz.
Equivalente a ` at(size() - 1)`.
Veja também at().
void QJsonArray::pop_back()
Esta função é fornecida para fins de compatibilidade com a STL. É equivalente a ` removeLast()`. A matriz não deve estar vazia. Se a matriz puder estar vazia, chame ` isEmpty()` antes de chamar esta função.
void QJsonArray::pop_front()
Esta função é fornecida para fins de compatibilidade com a STL. É equivalente a ` removeFirst()`. A matriz não deve estar vazia. Se for possível que a matriz esteja vazia, chame ` isEmpty()` antes de chamar esta função.
void QJsonArray::prepend(const QJsonValue &value)
Inser value no início da matriz.
Isso equivale a ` insert(0, value) ` e irá adicionar ` value ` no início do array.
Veja também append() e insert().
void QJsonArray::push_back(const QJsonValue &value)
Esta função é fornecida para garantir a compatibilidade com a STL. É equivalente a ` append(value)` e acrescentará ` value ` à matriz.
void QJsonArray::push_front(const QJsonValue &value)
Esta função é fornecida para fins de compatibilidade com a STL. É equivalente a ` prepend(value)` e irá inserir ` value ` no início da matriz.
void QJsonArray::removeAt(qsizetype i)
Remove o valor na posição de índice i. i deve ser uma posição de índice válida na matriz (ou seja, 0 <= i < size()).
Veja também insert() e replace().
void QJsonArray::removeFirst()
Remove o primeiro item da matriz. Chamar essa função é equivalente a chamar removeAt(0). A matriz não deve estar vazia. Se a matriz puder estar vazia, chame isEmpty() antes de chamar essa função.
Veja também removeAt() e removeLast().
void QJsonArray::removeLast()
Remove o último item da matriz. Chamar esta função é equivalente a chamar removeAt(size() - 1). A matriz não deve estar vazia. Se a matriz puder estar vazia, chame isEmpty() antes de chamar esta função.
Veja também removeAt() e removeFirst().
void QJsonArray::replace(qsizetype i, const QJsonValue &value)
Substitui o item na posição de índice i por value. i deve ser uma posição de índice válida na matriz (ou seja, 0 <= i < size()).
Veja também operator[]() e removeAt().
qsizetype QJsonArray::size() const
Retorna o número de valores armazenados na matriz.
[noexcept] void QJsonArray::swap(QJsonArray &other)
Troca os elementos deste array com os d other. Essa operação é muito rápida e nunca falha.
QJsonValue QJsonArray::takeAt(qsizetype i)
Remove o item na posição de índice i e o retorna. i deve ser uma posição de índice válida na matriz (ou seja, 0 <= i < size()).
Se você não usar o valor de retorno, removeAt() é mais eficiente.
Veja também removeAt().
QVariantList QJsonArray::toVariantList() const
Converte este objeto em um ` QVariantList`.
Retorna o mapa criado.
QJsonArray QJsonArray::operator+(const QJsonValue &value) const
Retorna um array que contém todos os itens deste array, seguidos pelo parâmetro ` value` fornecido.
Veja também operator+=().
QJsonArray &QJsonArray::operator+=(const QJsonValue &value)
Acrescenta value à matriz e retorna uma referência à própria matriz.
Veja também append() e operator<<().
QJsonArray &QJsonArray::operator<<(const QJsonValue &value)
Acrescenta value à matriz e retorna uma referência à própria matriz.
Veja também operator+=() e append().
[noexcept] QJsonArray &QJsonArray::operator=(QJsonArray &&other)
A instrução `move` atribui ` other ` a essa matriz.
[noexcept] QJsonArray &QJsonArray::operator=(const QJsonArray &other)
Atribui ` other ` a este array.
QJsonValueRef QJsonArray::operator[](qsizetype i)
Retorna o valor na posição de índice i como uma referência modificável. i deve ser uma posição de índice válida na matriz (ou seja, 0 <= i < size()).
O valor retornado é do tipo QJsonValueRef, uma classe auxiliar para QJsonArray e QJsonObject. Ao obter um objeto do tipo QJsonValueRef, você pode usá-lo como se fosse uma referência a um QJsonValue. Se você atribuir um valor a ele, a atribuição se aplicará ao caractere na QJsonArray de QJsonObject a partir da qual você obteve a referência.
Veja também at().
QJsonValue QJsonArray::operator[](qsizetype i) const
É igual a at().
Esta é uma função sobrecarregada.
Não-membros relacionados
[noexcept] bool operator!=(const QJsonArray &lhs, const QJsonArray &rhs)
Retorna ` true ` se a matriz ` lhs ` não for igual a ` rhs`; caso contrário, retorna ` false `.
[noexcept] bool operator==(const QJsonArray &lhs, const QJsonArray &rhs)
Retorna ` true ` se a matriz ` lhs ` for igual a ` rhs`; caso contrário, retorna ` false `.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.