Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qjsondocument.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QJSONDOCUMENT_H
5#define QJSONDOCUMENT_H
6
7#include <QtCore/qcompare.h>
8#include <QtCore/qjsonvalue.h>
9#include <QtCore/qscopedpointer.h>
10
11#include <memory>
12
14
15class QDebug;
16class QCborValue;
17
18namespace QJsonPrivate { class Parser; }
19
45
47class Q_CORE_EXPORT QJsonDocument
48{
49public:
50#ifdef Q_LITTLE_ENDIAN
51 static const uint BinaryFormatTag = ('q') | ('b' << 8) | ('j' << 16) | ('s' << 24);
52#else
53 static const uint BinaryFormatTag = ('q' << 24) | ('b' << 16) | ('j' << 8) | ('s');
54#endif
55
57 explicit QJsonDocument(const QJsonObject &object);
58 explicit QJsonDocument(const QJsonArray &array);
60
62 QJsonDocument &operator =(const QJsonDocument &other);
63
65
66 QJsonDocument &operator =(QJsonDocument &&other) noexcept
67 {
68 swap(other);
69 return *this;
70 }
71
72 void swap(QJsonDocument &other) noexcept;
73
74 static QJsonDocument fromVariant(const QVariant &variant);
75 QVariant toVariant() const;
76
79 Compact
80 };
81
82 static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = nullptr);
83
84#if !defined(QT_JSON_READONLY) || defined(Q_QDOC)
85 QByteArray toJson(JsonFormat format = Indented) const;
86#endif
87
88 bool isEmpty() const;
89 bool isArray() const;
90 bool isObject() const;
91
92 QJsonObject object() const;
93 QJsonArray array() const;
94
95 void setObject(const QJsonObject &object);
96 void setArray(const QJsonArray &array);
97
98 const QJsonValue operator[](const QString &key) const;
99 const QJsonValue operator[](QStringView key) const;
100 const QJsonValue operator[](QLatin1StringView key) const;
101 const QJsonValue operator[](qsizetype i) const;
102#if QT_CORE_REMOVED_SINCE(6, 8)
103 bool operator==(const QJsonDocument &other) const;
104 bool operator!=(const QJsonDocument &other) const { return !operator==(other); }
105#endif
106 bool isNull() const;
107
108private:
109 friend class QJsonValue;
111 friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
112 friend Q_CORE_EXPORT bool comparesEqual(const QJsonDocument &lhs,
113 const QJsonDocument &rhs) noexcept;
115
117
118 std::unique_ptr<QJsonDocumentPrivate> d;
119};
120
121Q_DECLARE_SHARED(QJsonDocument)
122
123#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
124Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
125#endif
126
127#ifndef QT_NO_DATASTREAM
128Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QJsonDocument &);
130#endif
131
133
134#endif // QJSONDOCUMENT_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qcborvalue.h:47
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qjsonarray.h:18
\inmodule QtCore\reentrant
~QJsonDocument()
Deletes the document.
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
\inmodule QtCore\reentrant
Definition qjsonvalue.h:25
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
bool isNull(const T &t)
#define Q_DECLARE_EQUALITY_COMPARABLE(...)
constexpr bool operator!=(const timespec &t1, const timespec &t2)
DBusConnection const char DBusError * error
bool comparesEqual(const QDir &lhs, const QDir &rhs)
Definition qdir.cpp:1819
Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &)
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &, QJsonDocument &)
static QCborValue fromJson(const QByteArray &json, QJsonParseError *error)
GLuint64 key
GLuint object
[3]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLenum array
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
@ NoError
Definition main.cpp:34
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QVariant variant
[1]
QSharedPointer< T > other(t)
[5]
this swap(other)
\inmodule QtCore\reentrant
ParseError
This enum describes the type of error that occurred during the parsing of a JSON document.