QJsonDocument Class
QJsonDocument 클래스는 JSON 문서를 읽고 쓰는 방법을 제공합니다. 더 보기...
Header: | #include <QJsonDocument> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
- 상속된 멤버를 포함한 모든 멤버의 목록
- QJsonDocument는 Qt의 JSON 지원과 암시적으로 공유되는 클래스의 일부입니다.
이 클래스는 동등 비교가 가능합니다.
참고: 이 클래스의 모든 함수는 재인용됩니다.
공용 유형
enum | JsonFormat { Indented, Compact } |
공용 함수
QJsonDocument() | |
QJsonDocument(const QJsonArray &array) | |
QJsonDocument(const QJsonObject &object) | |
QJsonDocument(const QJsonDocument &other) | |
QJsonDocument(QJsonDocument &&other) | |
~QJsonDocument() | |
QJsonArray | array() const |
bool | isArray() const |
bool | isEmpty() const |
bool | isNull() const |
bool | isObject() const |
QJsonObject | object() const |
void | setArray(const QJsonArray &array) |
void | setObject(const QJsonObject &object) |
void | swap(QJsonDocument &other) |
QByteArray | toJson(QJsonDocument::JsonFormat format = Indented) const |
QVariant | toVariant() const |
QJsonDocument & | operator=(QJsonDocument &&other) |
QJsonDocument & | operator=(const QJsonDocument &other) |
const QJsonValue | operator[](const QString &key) const |
const QJsonValue | operator[](qsizetype i) const |
const QJsonValue | operator[](QLatin1StringView key) const |
const QJsonValue | operator[](QStringView key) const |
정적 공용 멤버
QJsonDocument | fromJson(const QByteArray &json, QJsonParseError *error = nullptr) |
QJsonDocument | fromVariant(const QVariant &variant) |
관련 비회원
bool | operator!=(const QJsonDocument &lhs, const QJsonDocument &rhs) |
bool | operator==(const QJsonDocument &lhs, const QJsonDocument &rhs) |
상세 설명
QJsonDocument는 완전한 JSON 문서를 래핑하는 클래스이며, 이 문서를 UTF-8로 인코딩된 텍스트 기반 표현에서 읽고 쓸 수 있습니다.
JSON 문서는 QJsonDocument::fromJson()를 사용하여 텍스트 기반 표현에서 QJsonDocument로 변환할 수 있습니다. toJson()를 사용하면 다시 텍스트로 변환됩니다. 구문 분석기는 매우 빠르고 효율적이며 JSON을 Qt에서 사용하는 바이너리 표현으로 변환합니다.
구문 분석된 문서의 유효성은 !isNull()로 쿼리할 수 있습니다.
isArray() 및 isObject()를 사용하여 문서에 배열 또는 객체가 포함되어 있는지 여부를 쿼리할 수 있습니다. 문서에 포함된 배열 또는 객체는 array() 또는 object()를 사용하여 검색한 다음 읽거나 조작할 수 있습니다.
Qt의 JSON 지원 및 게임 저장 및 로드도참조하세요 .
멤버 유형 문서
enum QJsonDocument::JsonFormat
이 값은 toJson()를 사용하여 QJsonDocument 로 변환할 때 생성되는 JSON 바이트 배열의 형식을 정의합니다.
상수 | 값 | 설명 |
---|---|---|
QJsonDocument::Indented | 0 | 사람이 읽을 수 있는 출력을 다음과 같이 정의합니다:{ "Array": [ true, 999, "string" ], "Key": "Value", "null": null } |
QJsonDocument::Compact | 1 | 다음과 같이 간결한 출력을 정의합니다:{"Array":[true,999,"string"],"Key":"Value","null":null} |
멤버 함수 문서
QJsonDocument::QJsonDocument()
비어 있고 유효하지 않은 문서를 작성합니다.
[explicit]
QJsonDocument::QJsonDocument(const QJsonArray &array)
array 에서 QJsonDocument를 생성합니다.
[explicit]
QJsonDocument::QJsonDocument(const QJsonObject &object)
object 에서 QJsonDocument를 생성합니다.
QJsonDocument::QJsonDocument(const QJsonDocument &other)
other 문서의 복사본을 만듭니다.
[noexcept]
QJsonDocument::QJsonDocument(QJsonDocument &&other)
이동 - other 에서 QJsonDocument를 생성합니다.
[noexcept]
QJsonDocument::~QJsonDocument()
문서를 삭제합니다.
fromRawData가 포함된 이진 데이터 집합은 해제되지 않습니다.
QJsonArray QJsonDocument::array() const
문서에 포함된 QJsonArray 을 반환합니다.
문서에 객체가 포함된 경우 빈 배열을 반환합니다.
isArray(), object() 및 setArray()도 참조하세요 .
[static]
QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error = nullptr)
json 을 UTF-8로 인코딩된 JSON 문서로 구문 분석하고 QJsonDocument 을 생성합니다.
구문 분석에 성공하면 유효한(널이 아닌) QJsonDocument 을 반환합니다. 실패하면 반환되는 문서는 null이 되고 선택적 error 변수에 오류에 대한 자세한 정보가 포함됩니다.
toJson(), QJsonParseError, isNull()도 참조하세요 .
[static]
QJsonDocument QJsonDocument::fromVariant(const QVariant &variant)
QVariant variant 에서 QJsonDocument 을 생성합니다.
variant 에 QVariantMap, QVariantHash, QVariantList 또는 QStringList 이외의 다른 유형이 포함된 경우 반환된 문서는 유효하지 않습니다.
toVariant()도 참조하세요 .
bool QJsonDocument::isArray() const
문서에 배열이 포함된 경우 true
을 반환합니다.
bool QJsonDocument::isEmpty() const
문서에 데이터가 없는 경우 true
을 반환합니다.
bool QJsonDocument::isNull() const
이 문서가 null인 경우 true
을 반환합니다.
널 문서는 기본 생성자를 통해 생성된 문서입니다.
UTF-8로 인코딩된 텍스트 또는 바이너리 형식으로 생성된 문서는 구문 분석 중에 유효성 검사가 이루어집니다. 유효성 검사에 실패하면 반환되는 문서도 null이 됩니다.
bool QJsonDocument::isObject() const
문서에 객체가 포함되어 있으면 true
을 반환합니다.
QJsonObject QJsonDocument::object() const
문서에 포함된 QJsonObject 을 반환합니다.
문서에 배열이 포함된 경우 빈 객체를 반환합니다.
isObject(), array() 및 setObject()도 참조하세요 .
void QJsonDocument::setArray(const QJsonArray &array)
array 을 이 문서의 주 객체로 설정합니다.
setObject() 및 array()도 참조하세요 .
void QJsonDocument::setObject(const QJsonObject &object)
object 을 이 문서의 주 객체로 설정합니다.
setArray() 및 object()도 참조하세요 .
[noexcept]
void QJsonDocument::swap(QJsonDocument &other)
이 문서를 other 로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.
QByteArray QJsonDocument::toJson(QJsonDocument::JsonFormat format = Indented) const
제공된 format 에서 QJsonDocument 을 UTF-8 인코딩된 JSON 문서로 변환합니다.
fromJson() 및 JsonFormat도 참조하세요 .
QVariant QJsonDocument::toVariant() const
Json 문서를 나타내는 QVariant 을 반환합니다.
반환되는 변형은 문서가 QJsonArray 인 경우 QVariantList, 문서가 QJsonObject 인 경우 QVariantMap 입니다.
fromVariant() 및 QJsonValue::toVariant()도 참조하세요 .
[noexcept]
QJsonDocument &QJsonDocument::operator=(QJsonDocument &&other)
이동-이 문서에 other 주소를 할당합니다.
QJsonDocument &QJsonDocument::operator=(const QJsonDocument &other)
other 문서를 이 QJsonDocument 에 할당합니다. 이 객체에 대한 참조를 반환합니다.
const QJsonValue QJsonDocument::operator[](const QString &key) const
key 키의 값을 나타내는 QJsonValue 를 반환합니다.
object().value(키)를 호출하는 것과 동일합니다.
키가 존재하지 않거나 isObject()가 거짓인 경우 반환되는 QJsonValue 은 QJsonValue::Undefined 입니다.
QJsonValue, QJsonValue::isUndefined() 및 QJsonObject 를참조하세요 .
const QJsonValue QJsonDocument::operator[](qsizetype i) const
색인 i 의 값을 나타내는 QJsonValue 을 반환합니다.
array().at(i)를 호출하는 것과 동일합니다.
i 이 범위를 벗어나거나 isArray()가 거짓인 경우 반환되는 QJsonValue 은 QJsonValue::Undefined 입니다.
QJsonValue, QJsonValue::isUndefined() 및 QJsonArray 를참조하세요 .
const QJsonValue QJsonDocument::operator[](QLatin1StringView key) const
과부하가 걸린 기능입니다.
const QJsonValue QJsonDocument::operator[](QStringView key) const
과부하가 걸린 기능입니다.
관련 비회원
[noexcept]
bool operator!=(const QJsonDocument &lhs, const QJsonDocument &rhs)
lhs 문서가 rhs 문서와 같지 않으면 true
, 그렇지 않으면 false
을 반환합니다.
[noexcept]
bool operator==(const QJsonDocument &lhs, const QJsonDocument &rhs)
lhs 문서가 rhs 문서와 같으면 true
, 그렇지 않으면 false
을 반환합니다.
© 2025 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.