Qt写的代码生成器
1.根据json对象或者数组自动生成json相关代码
示例json数据
{
"data": {
"count": 0,
"orderId": null,
"queryOrderWaitTimeStatus": true,
"requestId": 6297781498717690000,
"tourFlag": "dc",
"waitCount": 1,
"waitTime": 4
},
"httpstatus": 200,
"messages": [
],
"status": true,
"validateMessages": {
},
"validateMessagesShowId": "_validatorMessage"
}
自动生成的代码
```cpp
// 构建Json父对象
QJsonObject parentObject;
// 构建Parent子对象childObject1_1
QJsonObject childObject1_1;
childObject1_1.insert("count", 0);
QJsonValue nullValue;
childObject1_1.insert("orderId", nullValue);
childObject1_1.insert("queryOrderWaitTimeStatus", 1);
childObject1_1.insert("requestId", 6.29778e+18);
childObject1_1.insert("tourFlag", "dc");
childObject1_1.insert("waitCount", 1);
childObject1_1.insert("waitTime", 4);
parentObject.insert("data", QJsonValue(childObject1_1));
parentObject.insert("httpstatus", 200);
// 构建Json数组
QJsonArray childArray1_2;
parentObject.insert("messages", QJsonValue(childArray1_2));
parentObject.insert("status", 1);
// 构建Parent子对象childObject1_3
QJsonObject childObject1_3;
parentObject.insert("validateMessages", QJsonValue(childObject1_3));
parentObject.insert("validateMessagesShowId", "_validatorMessage");
// 构建 JsonDocument 文档
QJsonDocument jsonDocument;
jsonDocument.setObject(parentObject);
QByteArray jsonByteArray = jsonDocument.toJson(QJsonDocument::Compact);
2.根据get或者post相关数据,自动生成QUrlQuery对
示例URL
```cpp
https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand
自动生成
QString baseUrl = "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew";
QUrlQuery urlQuery;
urlQuery.addQueryItem("module", "login");
urlQuery.addQueryItem("rand", "sjrand");
QString getEncode = urlQuery.query(QUrl::FullyEncoded);//自动去除问号
QString getUrl = baseUrl + "?" + getEncode;