QJsonDocument Class
QJsonDocument 클래스는 JSON 문서를 읽고 쓰는 기능을 제공합니다. 더 보기...
| 헤더: | #include <QJsonDocument> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
- 상속된 멤버를 포함한 모든 멤버 목록
- QJsonDocument는 Qt의 JSON 지원 및 암시적 공유 클래스의 일부입니다.
참고: 이 클래스의 모든 함수는 재진입 가능합니다.
QJsonDocument 비교
| 범주 | 비교 가능한 유형 |
|---|---|
| 동등성 | QJsonDocument |
공개 유형
| enum | JsonFormat { Indented, Compact } |
공개 함수
| QJsonDocument() | |
(since 6.12) | QJsonDocument(QJsonArray &&array) |
(since 6.12) | QJsonDocument(QJsonObject &&object) |
| 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 = JsonFormat::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 | 다음과 같이 사람이 읽을 수 있는 형식의 출력을 정의합니다: |
QJsonDocument::Compact | 1 | 다음과 같이 간결한 출력을 정의합니다: |
멤버 함수 문서
QJsonDocument::QJsonDocument()
비어 있고 유효하지 않은 문서를 생성합니다.
[explicit, since 6.12] QJsonDocument::QJsonDocument(QJsonArray &&array)
array 에서 QJsonDocument를 생성합니다.
이 함수는 Qt 6.12에서 도입되었습니다.
[explicit, since 6.12] QJsonDocument::QJsonDocument(QJsonObject &&object)
object 에서 QJsonDocument를 생성합니다.
이 함수는 Qt 6.12에서 도입되었습니다.
[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 객체를 생성합니다.
구문 분석에 성공하면 유효한(null이 아닌) 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 를 반환합니다.
array() 및 isObject()도 참조하십시오 .
bool QJsonDocument::isEmpty() const
문서에 데이터가 포함되어 있지 않으면 ` true `를 반환합니다.
bool QJsonDocument::isNull() const
이 문서가 null인 경우 ` true `을 반환합니다.
null 문서는 기본 생성자를 통해 생성된 문서입니다.
UTF-8 인코딩된 텍스트나 바이너리 형식으로 생성된 문서는 구문 분석 과정에서 유효성 검증을 거칩니다. 유효성 검증이 실패하면 반환되는 문서도 null이 됩니다.
bool QJsonDocument::isObject() const
문서에 객체가 포함되어 있으면 true 를 반환합니다.
object() 및 isArray()도 참조하십시오 .
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 = JsonFormat::Indented) const
QJsonDocument 를 제공된 format 형식의 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(key)를 호출하는 것과 동일합니다.
키가 존재하지 않거나 isObject()의 결과가 false인 경우, 반환되는 QJsonValue 는 QJsonValue::Undefined 입니다.
QJsonValue, QJsonValue::isUndefined(), QJsonObject도 참조하십시오 .
const QJsonValue QJsonDocument::operator[](qsizetype i) const
인덱스 i 의 값을 나타내는 ` QJsonValue `를 반환합니다.
array().at(i)를 호출하는 것과 동일합니다.
i 가 범위를 벗어났거나 isArray()가 false인 경우, 반환되는 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 을 반환합니다.
© 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.