#include "include/httpthreadnum1.h" #include #include #include TOnDevInfoChange callbackDevInfoChange; int EC_SetOnDevInfoChange(TOnDevInfoChange onChange, void* pUser); QString g_qsToken; //扩展 QMutex g_QMutex_token; HttpThreadNum1::HttpThreadNum1() { //初始化postApi //在地址列表map中加入对应的地址 //参数:数据类型和url地址 m_HTN1MapApi.insert(EHTN1TYPE_LoginInfo, m_qsServiceUrl + "/token/api"); m_HTN1MapApi.insert(EHTN1TYPE_GetAllCarState, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_DoStartUpCar, m_qsServiceUrl + "/v5/api"); //新增接口 m_HTN1MapApi.insert(EHTN1TYPE_ShutDownCar, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_RemoteRequest, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_DoStartWorkCar, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_AddCar, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_RenameCar, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_DeleteCar, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_TaskList, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_StopTask, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_CancelTask, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_GetSlagState, m_qsServiceUrl + "/v5/api"); m_HTN1MapApi.insert(EHTN1TYPE_GetWarningState, m_qsServiceUrl + "/v5/api"); //创建一个空的Qlist容器 QList listTemp; //QVariant通用类型 for (int i = 0; i < EHTN1TYPE_max; i++) { m_listStructReady.insert(i, listTemp); } } void HttpThreadNum1::init() { //使用qt自带的start启动线程 this->start(); } //适用于两种结构体类型所以使用void,传入后再分配强转成对应的类型 //参数iType是QMap的键,structData是QMap的值列表中内容的地址 //作用:将数据传入到双层容器中 void HttpThreadNum1::postData(int iType, void* structData) { m_QMutex.lock(); //创建一个接收QMap的值列表中的内容的变量 QVariant qvariant; if (iType == EHTN1TYPE_LoginInfo) { qvariant = QVariant::fromValue(*((S_HTN1_LoginInfo*)structData)); //将自定义结构体类型转换为QVariant类型 } else if (iType == EHTN1TYPE_GetAllCarState) { qvariant = QVariant::fromValue(*((S_HTN1_GetAllCarState*)structData)); } else if (iType == EHTN1TYPE_DoStartUpCar) { qvariant = QVariant::fromValue(*((S_HTN1_DoStartUpCar*)structData)); } //新增双层容器加数据 else if (iType == EHTN1TYPE_ShutDownCar) { qvariant = QVariant::fromValue(*((S_HTN1_ShutDownCar*)structData)); } else if (iType == EHTN1TYPE_RemoteRequest) { qvariant = QVariant::fromValue(*((S_HTN1_RemoteRequest*)structData)); } else if (iType == EHTN1TYPE_DoStartWorkCar) { qvariant = QVariant::fromValue(*((S_HTN1_DoStartWorkCar*)structData)); } else if (iType == EHTN1TYPE_AddCar) { qvariant = QVariant::fromValue(*((S_HTN1_AddCar*)structData)); } else if (iType == EHTN1TYPE_RenameCar) { qvariant = QVariant::fromValue(*((S_HTN1_RenameCar*)structData)); } else if (iType == EHTN1TYPE_DeleteCar) { qvariant = QVariant::fromValue(*((S_HTN1_DeleteCar*)structData)); } else if (iType == EHTN1TYPE_TaskList) { qvariant = QVariant::fromValue(*((S_HTN1_TaskList*)structData)); } else if (iType == EHTN1TYPE_StopTask) { qvariant = QVariant::fromValue(*((S_HTN1_StopTask*)structData)); } else if (iType == EHTN1TYPE_CancelTask) { qvariant = QVariant::fromValue(*((S_HTN1_CancelTask*)structData)); } else if (iType == EHTN1TYPE_GetSlagState) { qvariant = QVariant::fromValue(*((S_HTN1_GetSlagState*)structData)); } else if (iType == EHTN1TYPE_GetWarningState) { qvariant = QVariant::fromValue(*((S_HTN1_GetWarningState*)structData)); } //使用下标操作符 [] 直接访问 QMap 中键为 iType 的值,该值是一个 QList 对象。 //然后使用 append 函数将 qvariant 添加到该列表的末尾。 //如果键 iType 在 m_listStructReady 中不存在,则会自动创建一个新的键值对,其中键为 iType,值为包含 qvariant 的新列表。 m_listStructReady[iType].append(qvariant); m_QMutex.unlock(); } void HttpThreadNum1::setToken(QString qsTok) { g_QMutex_token.lock(); g_qsToken = qsTok; g_QMutex_token.unlock(); } //初始化的时候调用,启动线程 void HttpThreadNum1::run() { //为什么要创建 HttpClient 对象===为了可以在priPostData中调用HttpClient类的postQString方法 HttpClient* m_pHttpClient = new HttpClient; while (true) { //创建一个临时的QMap映射容器存储请求数据队列 QMap> mapTemp; //清空全局的QMap映射容器,清空的时候加锁,防止和写入的时候冲突 m_QMutex.lock(); mapTemp = m_listStructReady; for (int i = 0; i < EHTN1TYPE_max; i++) { m_listStructReady[i].clear(); } m_QMutex.unlock(); //创建一个迭代器 QMap>::iterator iter; //遍历临时的QMap映射容器 for (iter = mapTemp.begin(); iter != mapTemp.end(); iter++) { if (iter.value().count() > 0) { //遍历QList请求数据队列 for (int i = 0; i < iter.value().count(); i++) { //将QMap中的所有内容全部发出去 priPostData(iter.key(), iter.value()[i], m_pHttpClient); } } } msleep(10); } //TODO:回调 //callbackDevInfoChange(iTemp,msg); } //将请求数据队列发送给服务器,并接收服务器返回的数据 void HttpThreadNum1::priPostData(int iType, QVariant structData, void* voidPointer) { QVariant resultQVariant; //post请求数据 //判断类型是登录消息类型 if (iType == EHTN1TYPE_LoginInfo) { //创建一个结构体 S_HTN1_LoginReturn resultStruct; //接收登录信息的内容 S_HTN1_LoginInfo structTemp = structData.value(); //设置错误字段 QString qsError = "出错"; //设置接收到的字符串变量 QString qsRevData = ""; //实际上发过去的是string,使用json转是为了方便拼接 QJsonObject qjsonObject; qjsonObject.insert("username", structTemp.username); qjsonObject.insert("password", structTemp.password); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring //postQString中传入url地址,登录的账号密码qstring类型的数据,报错信息,接收到的字符串 //postQString返回为true的时候执行 if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; //将接收到的json数据保存到json文件中 QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); //这里也可以不用做错误判断 if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 //将json对象中的内容传入结构体resultStruct中 if (object.contains("message")) { resultStruct.message = object.value("message").toVariant().toString(); } if (object.contains("uid")) { resultStruct.uid = object.value("uid").toVariant().toString(); } if (object.contains("role_name")) { resultStruct.role_name = object.value("role_name").toVariant().toString(); } if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } } } //将结构体转换为QVariant类型 emit sig_result(EHTN1TYPE_LoginReturn, QVariant::fromValue(*((S_HTN1_LoginReturn*)&resultStruct))); } else { // qDebug()<<"连接失败"<<"发送连接失败信号"; emit sig_result(EHTN1TYPE_LoginReturn, EHTN1TYPE_error); } } else if (iType == EHTN1TYPE_GetAllCarState) { S_HTN1_ReturnAllCarState resultStruct; S_HTN1_GetAllCarState structTemp = structData.value(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { //数组的转成document固定写法 QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant()); // if (variant.type() == QVariant::String) { if (!doucment2.isArray()) { qDebug() << "不是数组"; } //数组 QJsonArray tempQJsonArray = doucment2.array(); for (int i = 0; i < tempQJsonArray.count(); i++) { // 解析未发生错误 if (tempQJsonArray[i].isObject()) { if (tempQJsonArray[i].isObject()) { // JSON文档为对象 S_HTN1_ReturnOneCarState sOneStruct; QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象 if (object.contains("uuid")) { sOneStruct.uuid = object.value("uuid").toVariant().toString(); } if (object.contains("name")) { sOneStruct.name = object.value("name").toVariant().toString(); } if (object.contains("state")) { sOneStruct.state = object.value("state").toVariant().toInt(); } if (object.contains("check_vehicle_direction")) { sOneStruct.check_vehicle_direction = object.value("check_vehicle_direction").toVariant().toBool(); } if (object.contains("address")) { sOneStruct.address = object.value("address").toVariant().toString(); } if (object.contains("current_vehicle_direction")) { sOneStruct.current_vehicle_direction = object.value("current_vehicle_direction").toVariant().toInt(); } if (object.contains("current_vehicle_weight")) { sOneStruct.current_vehicle_weight = object.value("current_vehicle_weight").toVariant().toInt(); } if (object.contains("vehicle_pot_state")) { sOneStruct.vehicle_pot_state = object.value("vehicle_pot_state").toVariant().toInt(); } resultStruct.data.append(sOneStruct); } } } // } } } } emit sig_result(EHTN1TYPE_ReturnAllCarState, QVariant::fromValue(*((S_HTN1_ReturnAllCarState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnStartUpState, QVariant::fromValue(*((S_HTN1_ReturnStartUpState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnShutDownState, QVariant::fromValue(*((S_HTN1_ReturnShutDownState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnRemoteRequestState, QVariant::fromValue(*((S_HTN1_ReturnRemoteRequestState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); qjsonObject.insert("task_type", structTemp.task_type); qjsonObject.insert("target_point_name", structTemp.target_point_name); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnStartWorkState, QVariant::fromValue(*((S_HTN1_ReturnDoStartWorkState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("name", structTemp.name); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnAddCarState, QVariant::fromValue(*((S_HTN1_ReturnAddCarState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); qjsonObject.insert("name", structTemp.name); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { //数组的转成document固定写法 QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant()); //数组 QJsonArray tempQJsonArray = doucment2.array(); for (int i = 0; i < tempQJsonArray.count(); i++) { // 解析未发生错误 if (tempQJsonArray[i].isObject()) { if (tempQJsonArray[i].isObject()) { // JSON文档为对象 S_HTN1_ReturnReanmeCarState_data sOneStruct; QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象 if (object.contains("uuid")) { sOneStruct.uuid = object.value("uuid").toVariant().toString(); } if (object.contains("name")) { sOneStruct.name = object.value("name").toVariant().toString(); } if (object.contains("update_at")) { sOneStruct.update_at = object.value("update_at").toVariant().toInt(); } resultStruct.data.append(sOneStruct); } } } } } } emit sig_result(EHTN1TYPE_ReturnRenameCarState, QVariant::fromValue(*((S_HTN1_ReturnReanmeCarState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnDeleteCarState, QVariant::fromValue(*((S_HTN1_ReturnDeleteCarState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("page", structTemp.page); qjsonObject.insert("size", structTemp.size); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("page")) { resultStruct.page = object.value("page").toVariant().toInt(); } if (object.contains("size")) { resultStruct.size = object.value("size").toVariant().toInt(); } if (object.contains("total")) { resultStruct.total = object.value("total").toVariant().toInt(); } if (object.contains("data")) { //数组的转成document固定写法 QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant()); //数组 QJsonArray tempQJsonArray = doucment2.array(); for (int i = 0; i < tempQJsonArray.count(); i++) { // 解析未发生错误 if (tempQJsonArray[i].isObject()) { if (tempQJsonArray[i].isObject()) { // JSON文档为对象 S_HTN1_ReturnTaskListData_data sOneStruct; QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象 if (object.contains("uuid")) { sOneStruct.uuid = object.value("uuid").toVariant().toString(); } if (object.contains("vehicle_uuid")) { sOneStruct.vehicle_uuid = object.value("vehicle_uuid").toVariant().toString(); } if (object.contains("task_type")) { sOneStruct.task_type = object.value("task_type").toVariant().toInt(); } if (object.contains("target_point_name")) { sOneStruct.target_point_name = object.value("target_point_name").toVariant().toString(); } if (object.contains("task_state")) { sOneStruct.task_state = object.value("task_state").toVariant().toInt(); } if (object.contains("create_at")) { sOneStruct.create_at = object.value("create_at").toVariant().toInt(); } resultStruct.data.append(sOneStruct); } } } } } } emit sig_result(EHTN1TYPE_ReturnTaskListData, QVariant::fromValue(*((S_HTN1_ReturnTaskListData*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnStopTask, QVariant::fromValue(*((S_HTN1_ReturnStopTask*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); qjsonObject.insert("uuid", structTemp.uuid); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { resultStruct.data = object.value("data").toVariant().toString(); } } } emit sig_result(EHTN1TYPE_ReturnCancelTask, QVariant::fromValue(*((S_HTN1_ReturnCancelTask*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { //数组的转成document固定写法 QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant()); //数组 QJsonArray tempQJsonArray = doucment2.array(); for (int i = 0; i < tempQJsonArray.count(); i++) { // 解析未发生错误 if (tempQJsonArray[i].isObject()) { if (tempQJsonArray[i].isObject()) { // JSON文档为对象 S_HTN1_ReturnSlagState_data sOneStruct; QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象 if (object.contains("pot_name")) { sOneStruct.pot_name = object.value("pot_name").toVariant().toString(); } if (object.contains("pot_status")) { sOneStruct.pot_status = object.value("pot_status").toVariant().toInt(); } if (object.contains("pot_number")) { sOneStruct.pot_number = object.value("pot_number").toVariant().toInt(); } resultStruct.data.append(sOneStruct); } } } } } } emit sig_result(EHTN1TYPE_ReturnSlagState, QVariant::fromValue(*((S_HTN1_ReturnSlagState*)&resultStruct))); // qDebug()<<"http列表成功"<(); QString qsError = "出错"; QString qsRevData = ""; QJsonObject qjsonObject; // qDebug()<code; qjsonObject.insert("code", structTemp.code); QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData)) { QJsonParseError jsonError; QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data()); if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误 if (doucment.isObject()) { // JSON 文档为对象 QJsonObject object = doucment.object(); // 转化为对象 if (object.contains("code")) { resultStruct.code = object.value("code").toVariant().toInt(); } if (object.contains("data")) { //数组的转成document固定写法 QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant()); //数组 QJsonArray tempQJsonArray = doucment2.array(); for (int i = 0; i < tempQJsonArray.count(); i++) { // 解析未发生错误 if (tempQJsonArray[i].isObject()) { if (tempQJsonArray[i].isObject()) { // JSON文档为对象 S_HTN1_ReturnWarningState_data sOneStruct; QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象 if (object.contains("message")) { sOneStruct.message = object.value("message").toVariant().toString(); } if (object.contains("create_at")) { sOneStruct.create_at = object.value("create_at").toVariant().toInt(); } resultStruct.data.append(sOneStruct); } } } } } } emit sig_result(EHTN1TYPE_ReturnWarningState, QVariant::fromValue(*((S_HTN1_ReturnWarningState*)&resultStruct))); // qDebug()<<"http列表成功"<