QtBase  v6.3.1
qjsondocument.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QJSONDOCUMENT_H
41 #define QJSONDOCUMENT_H
42 
43 #include <QtCore/qjsonvalue.h>
44 #include <QtCore/qscopedpointer.h>
45 
46 #include <memory>
47 
49 
50 class QDebug;
51 class QCborValue;
52 
53 namespace QJsonPrivate { class Parser; }
54 
55 struct Q_CORE_EXPORT QJsonParseError
56 {
57  enum ParseError {
58  NoError = 0,
72  GarbageAtEnd
73  };
74 
75  QString errorString() const;
76 
77  int offset = -1;
79 };
80 
82 class Q_CORE_EXPORT QJsonDocument
83 {
84 public:
85 #ifdef Q_LITTLE_ENDIAN
86  static const uint BinaryFormatTag = ('q') | ('b' << 8) | ('j' << 16) | ('s' << 24);
87 #else
88  static const uint BinaryFormatTag = ('q' << 24) | ('b' << 16) | ('j' << 8) | ('s');
89 #endif
90 
91  QJsonDocument();
92  explicit QJsonDocument(const QJsonObject &object);
93  explicit QJsonDocument(const QJsonArray &array);
95 
97  QJsonDocument &operator =(const QJsonDocument &other);
98 
99  QJsonDocument(QJsonDocument &&other) noexcept;
100 
101  QJsonDocument &operator =(QJsonDocument &&other) noexcept
102  {
103  swap(other);
104  return *this;
105  }
106 
107  void swap(QJsonDocument &other) noexcept;
108 
109  static QJsonDocument fromVariant(const QVariant &variant);
110  QVariant toVariant() const;
111 
112  enum JsonFormat {
114  Compact
115  };
116 
117  static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = nullptr);
118 
119 #if !defined(QT_JSON_READONLY) || defined(Q_CLANG_QDOC)
120  QByteArray toJson(JsonFormat format = Indented) const;
121 #endif
122 
123  bool isEmpty() const;
124  bool isArray() const;
125  bool isObject() const;
126 
127  QJsonObject object() const;
128  QJsonArray array() const;
129 
130  void setObject(const QJsonObject &object);
131  void setArray(const QJsonArray &array);
132 
133 #if QT_STRINGVIEW_LEVEL < 2
134  const QJsonValue operator[](const QString &key) const;
135 #endif
136  const QJsonValue operator[](QStringView key) const;
137  const QJsonValue operator[](QLatin1String key) const;
138  const QJsonValue operator[](qsizetype i) const;
139 
140  bool operator==(const QJsonDocument &other) const;
141  bool operator!=(const QJsonDocument &other) const { return !(*this == other); }
142 
143  bool isNull() const;
144 
145 private:
146  friend class QJsonValue;
147  friend class QJsonPrivate::Parser;
148  friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
149 
150  QJsonDocument(const QCborValue &data);
151 
152  std::unique_ptr<QJsonDocumentPrivate> d;
153 };
154 
156 
157 #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
158 Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
159 #endif
160 
161 #ifndef QT_NO_DATASTREAM
162 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QJsonDocument &);
163 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QJsonDocument &);
164 #endif
165 
167 
168 #endif // QJSONDOCUMENT_H
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
FT_Error error
Definition: cffdrivr.c:657
Definition: parser.h:39
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QCborValue class encapsulates a value in CBOR.
Definition: qcborvalue.h:86
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QJsonArray class encapsulates a JSON array.
Definition: qjsonarray.h:54
The QJsonDocument class provides a way to read and write JSON documents.
Definition: qjsondocument.h:83
bool operator!=(const QJsonDocument &other) const
The QJsonObject class encapsulates a JSON object.
Definition: qjsonobject.h:56
The QJsonValue class encapsulates a value in JSON.
Definition: qjsonvalue.h:60
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
Definition: qstring.h:84
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
Definition: qstringview.h:122
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
ptrdiff_t qsizetype
Definition: qglobal.h:308
unsigned int uint
Definition: qglobal.h:334
Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &)
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
GLuint64 key
GLuint object
[3]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLenum array
Definition: qopenglext.h:7028
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
QVariant variant
[1]
QSharedPointer< T > other(t)
[5]
this swap(other)
The QJsonParseError class is used to report errors during JSON parsing.
Definition: qjsondocument.h:56