JSON document operation for Qt learning

1. QJsonValue

1. Introduction
The QJsonValue class encapsulates the value in Json.
There are six basic types of Json values, you can use type() or isBool(), isString(), etc. to query the type of value. Similarly, you can use toBool(), toString(), etc. to convert a value into the type of value stored in Json.

Two, QJsonDocument

1. Introduction
Provides methods for reading and writing Json documents. FromJson() can be used to convert the textual form of a JSON document into a QJsonDocument object. toJSON() can convert QJsonDocument back to text form.

3. QJsonObject

1. Introduction
It is used to encapsulate JSON objects. A JSON object is a linked list containing key-value pairs, where the key is a unique string and its value is represented by a QJsonValue object. You can use size() to get the number of key-value pairs, and insert() and remove() are used to insert and delete pairs respectively. Its contents can be iterated using the standard C++ iterator pattern. ​QJsonObject and text format can be converted to each other through QJsonDocument.
2. Examples

QJsonObject json;
json.insert("Name", "Qt");//插入值
json.insert("From", 1991);
json.insert("Cross Platform", true);
// 构建 JSON 文档
QJsonDocument document;
document.setObject(json);

4. QJsonArray

1. Introduction
QJsonArray encapsulates Json array. A JSON array is a linked list of values, and QJsonValue can be inserted and deleted. You can use size(), insert(), removeAt() to operate, and you can use the standard C++ iterator mode to iterate its content.
2. Examples

//定义Json数组对象
QJsonArray array;
array.append(13);
array.append("itcast");
array.append(3.1415);
array.append(true);
//Json文档
QJsonDocument doc(array);
//转化为字节
QByteArray arr = doc.toJson();

5. An example of the integration of all things can be seen in the fifth point of complex Json generation and analysis in this link

For detailed examples
, you can use the following links to understand each operation class of Json documents in more detail
QJsonDocument class in Qt
QJsonArray class
in Qt QJsonObject class in
Qt QJsonValue class in Qt

Guess you like

Origin blog.csdn.net/m0_56626019/article/details/129854508