cjson调用的实例 c++
生活随笔
收集整理的這篇文章主要介紹了
cjson调用的实例 c++
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
主類中文定義
#include <QtGui/QApplication> #include <QTextCodec>QTextCodec::setCodecForTr(QTextCodec::codecForLocale());QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());宏定義:
enum dll_error_codes {STATUS_OK = 1, //成功狀態DOG_NOTFOUND=-1, //加密狗不存在DOG_INVVCODE = -2, //加密狗論證失敗DOG_SNERROR = -3, //加密狗序列號錯誤DOG_NOLOCAL =-4, //非本機加密狗DOG_GETDTAERROR =-5, //獲取加密狗數據失敗DOG_DATAERROR =-6, //加密狗數據非法DOG_CDSCOMERROR =-7, //服務器非本機加密狗硬盤序列號不匹配DOG_MACCOMERROR =-8, //服務器非本機加密狗MAC不匹配DOG_STATEERROR =-9, //加密狗使用狀態錯誤DOG_STATECLOSE =-10, //加密狗禁用DOG_TOOLERROR =-11, //工具類型不匹配DOG_TIMESRROR =-12, //注冊次數錯誤DOG_NOTIMES =-13, //注冊次數不足,請重新注冊DOG_VAILDATE =-14, //有效時間范圍錯誤DOG_WRITEERROR =-15, //加密狗寫入數據失敗DOG_REPLACERERROR =-16, //注冊時候拔出加密狗,更換了另外一個加密狗DOG_SERVERSN_ERROR =-17, //平臺下發序列號與本機獲取序列號不一致PC_TIMEERROR =-20, //本機電腦時間不正確PC_DOGDATAERROR =-21, //獲取本地磁盤與MAC失敗PC_DOG_CDSCOMERROR =-22,//非本機加密狗硬盤序列號不匹配PC_DOG_MACCOMERROR =-23,//非本機加密狗硬盤序列號不匹配PC_REGDATA_ERROR =-24, //接收到的PC注冊數據錯誤無法分割PC_REGTOOL_ERROR =-25, //平臺注冊類型不支持當前 工具PC_REGAUTH_NOERROR=-26, //授權碼不存在PC_REGAUTH_CKERROR =-27, //授權碼校驗值錯誤PC_REGAUTH_STATEERROR =-28, //授權碼狀態錯誤PC_TOOL_TYPEERROR =-29, //工具類型不正確,不能大于99SERVER_DOG_NOREGISTER =-30, //服務器加密狗不存在SERVER_DOG_CKERROR =-31, //加密狗校驗值錯誤SERVER_DOG_VENIDERROR =-32, //服務器加密狗VENID不匹配SERVER_DOG_DENIED =-33, //服務器禁用加密狗SERVER_DOG_DATAERROR =-34, //接收到服務器數據錯誤NET_PARM_ERROR =-40, //網絡參數錯誤IP端口配置錯誤config配置錯誤NET_WSAS_ERROR =-41, //網絡準備連接WSAStartup錯誤NET_CONN_ERROR =-42, //網絡連接錯誤NET_SEND_ERROR =-43, //網絡發送失敗NET_READ_ERROR =-44, //網絡接收失敗NET_DATA_INVALID =-45, //接收數據非法REG_OPEN_ERROR =-51, //打開注冊表失敗REG_DATA_ERROR =-52, //獲取注冊表信息失敗REG_WIITE_ERROR =-53, //寫入注冊表信息失敗COMMPORT_STATEERROR =-61, //通訊口未打開COMMPORT_READERROR =-62, //讀取數據失敗RSP_NO_TRAN = -94, //無此交易類型RSP_NO_PARSE=-95, //接收報文錯誤RSP_SYS_ERR =-96, //系統錯誤DATABASE_ERROR =-60, //服務器數據庫異常INIT_DENIED = -99, //動態庫未初始化};調用動態庫:
MinipaydllFunction.h
MinipaydllFunction.cpp
// MinipaydllFunction.cpp: implementation of the CMinipaydllFunction class. // // #include "MinipaydllFunction.h" #include <QMessageBox> #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif// // Construction/Destruction // CMinipaydllFunction::CMinipaydllFunction() {m_hlib = NULL; // m_hTranslib=NULL;init(); }CMinipaydllFunction::~CMinipaydllFunction() {}bool CMinipaydllFunction::init() {//QMessageBox::information(NULL, "Title", "調用開始", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);m_hlib = LoadLibrary(L"minipaydll.dll");if (m_hlib != NULL){//QMessageBox::information(NULL, "Title", "調用成功", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);m_InitDll =(InitDll)GetProcAddress(m_hlib, "InitDll");m_GetDogInfo =(GetDogInfo)GetProcAddress(m_hlib, "GetDogInfo");m_RegIsterDog =(RegIsterDog)GetProcAddress(m_hlib, "RegIsterDog"); m_OpenDevice = (OpenDevice)GetProcAddress(m_hlib, "OpenDevice");m_WriteSerialNum = (WriteSerialNum)GetProcAddress(m_hlib, "WriteSerialNum");m_Write21SnMainKey = (Write21SnMainKey)GetProcAddress(m_hlib, "Write21SnMainKey");m_WriteDateTime = (WriteDateTime)GetProcAddress(m_hlib, "WriteDateTime");m_ReduDogTimes = (ReduDogTimes)GetProcAddress(m_hlib, "ReduDogTimes"); m_TkVersion = (TkVersion)GetProcAddress(m_hlib, "TkVersion"); m_SaveBaseVersion = (SaveBaseVersion)GetProcAddress(m_hlib, "SaveBaseVersion");m_SaveRkVersion = (SaveRkVersion)GetProcAddress(m_hlib, "SaveRkVersion"); m_SelectBaseVersion = (SelectBaseVersion)GetProcAddress(m_hlib, "SelectBaseVersion");m_ReadSnVersion = (ReadSnVersion)GetProcAddress(m_hlib, "ReadSnVersion");m_SelectModelInfo = (SelectModelInfo)GetProcAddress(m_hlib, "SelectModelInfo");m_SelectProcColour = (SelectProcColour)GetProcAddress(m_hlib, "SelectProcColour"); // m_SelectProcName = (SelectProcName)GetProcAddress(m_hlib, "SelectProcName");m_Heartbeatpack = (Heartbeatpack)GetProcAddress(m_hlib, "Heartbeatpack");m_SelectSNAndTUSN = (SelectSNAndTUSN)GetProcAddress(m_hlib, "SelectSNAndTUSN");m_GetKeyToDevice = (GetKeyToDevice)GetProcAddress(m_hlib, "GetKeyToDevice");m_InfoReportSever = (InfoReportSever)GetProcAddress(m_hlib, "InfoReportSever"); m_ShouHouWeiXiu = (ShouHouWeiXiu)GetProcAddress(m_hlib, "ShouHouWeiXiu");m_ShouHouWeiXiuDetail = (ShouHouWeiXiuDetail)GetProcAddress(m_hlib, "ShouHouWeiXiuDetail");m_ShouHouInforToSQL = (ShouHouInforToSQL)GetProcAddress(m_hlib, "ShouHouInforToSQL");m_GetShouHouWeiXiuRecord = (GetShouHouWeiXiuRecord)GetProcAddress(m_hlib,"GetShouHouWeiXiuRecord"); //FreeLibrary(m_hlib);}else{return false;}m_hTranslib = LoadLibrary(L"secFunction.dll");if (m_hTranslib != NULL){ m_TransEncry = (TransEncry)GetProcAddress(m_hTranslib, "TransEncry");}m_hdoglib= LoadLibrary(L"dog_minipaydll.dll");if (m_hdoglib != NULL){m_checkSaftdog = (CheckSaftdog)GetProcAddress(m_hdoglib, "CheckSaftdog");m_useSaftdog = (UseSaftdog)GetProcAddress(m_hdoglib, "UseSaftdog");m_generatePollCode2 = (GeneratePollCode2)GetProcAddress(m_hdoglib, "GeneratePollCode2"); m_RegerSaftdogTimes = (RegerSaftdogTimes)GetProcAddress(m_hdoglib, "RegerSaftdogTimes");}else{return false;}return true; }主類函數.h
#ifndef SHOUHOUTOOL_H #define SHOUHOUTOOL_H#include "json/cJSON.h" #include "json/minipay_code.h" #include "MinipaydllFunction.h" #include <QtGui/QDialog> #include "ui_shouhoutool.h" #include <QMessageBox> #include <QMenu> #include <QSettings> #include <QtCore/QtCore> #include <QDebug> #include <QStandardItemModel> #include <QListWidgetItem> #include <QListWidget>#include "inputsn.h"class ShouHouTool : public QDialog {Q_OBJECTpublic:ShouHouTool(QWidget *parent = 0, Qt::WFlags flags = 0);~ShouHouTool();void InitPara();CMinipaydllFunction *g_minipaydllFunction;QString m_qstrfatherJieDian;LISTINTVector list1;LISTINTVector m_vecmain;LISTINTVector m_vecmini;QString m_qstrMain;QString m_qstrmini;int m_recordtableLine;void objconnect();void addconfigini();bool bjudcomb;int ShouHouWeiXiuDeal( char *VerBuf,int vsize,char *outBuf,int &outlen,LISTINTVector &listvector);int ShouHouWeiXiuDetailDeal( char *VerBuf,int vsize,int errcode);int GetShouHouWeiXiuRecord( char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode);static DWORD WINAPI ReadVersion(LPVOID pParam);//發送線程private slots:void on_exit();void slotLoadList(int);void SendToSQL();void getPadIds();/*按鈕添加*/void onbutaddtoDetailInformation();//void startThread(); private:Ui::ShouHouToolClass ui;void mousePressEvent (QMouseEvent * event ); };#endif // SHOUHOUTOOL_H主函數.cpp
#include "shouhoutool.h"ShouHouTool::ShouHouTool(QWidget *parent, Qt::WFlags flags): QDialog(parent, flags) {ui.setupUi(this);g_minipaydllFunction=new CMinipaydllFunction();objconnect();//addconfigini(); }ShouHouTool::~ShouHouTool() {delete[] g_minipaydllFunction; }void ShouHouTool::addconfigini() {QString ininame="";char tempbuf[1024]={0};char* tempname=NULL;QString iniFilePath = "/../config.ini"; iniFilePath = QCoreApplication::applicationDirPath() + "/Config.ini";QSettings settings(iniFilePath,QSettings::IniFormat); QString G1_fileName = settings.value("Setting/FactoryName").toString(); // ui.lineEdit_factory->setText(G1_fileName); }void ShouHouTool::objconnect() {//connect(ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(on_lineEdit_sendNew()));//沒有QString,一調用就會死connect(ui.pushButton_getInfo,SIGNAL(clicked()), this, SLOT(startThread()));//添加//connect(ui.tableWidget,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(deleteCurrentLine(QPoint)));return; } void ShouHouTool::InitPara() {//ui.lineEdit->setStyleSheet( normalStyle); }void ShouHouTool::on_exit() {QApplication* app;app->exit(0); }void ShouHouTool::slotLoadList(int i) {char ch[1024]={0};char outBuf[1024]={0x00};int outlen=0;int iErrCode=0;cJSON *rootdata;rootdata=cJSON_CreateObject();cJSON_AddStringToObject(rootdata,"info","");char *jsonBuf=cJSON_PrintUnformatted(rootdata);int result = g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);if(iErrCode!=0){QString qstrmessage=outBuf;QMessageBox::warning(this,tr("Warning"),qstrmessage);return ;}return; }void ShouHouTool::SendToSQL() {cJSON *rootdata;rootdata=cJSON_CreateObject();/*cJSON_AddStringToObject(rootdata,"FAC_ID","");cJSON_AddStringToObject(rootdata,"MIDDLE_CODE","");cJSON_AddStringToObject(rootdata,"SERIAL_NO","");cJSON_AddStringToObject(rootdata,"FAULT_CLASS","");cJSON_AddStringToObject(rootdata,"FAULT_CAUSE","");cJSON_AddStringToObject(rootdata,"RETEST_FAILURE","");cJSON_AddStringToObject(rootdata,"FAULT_NUM","");cJSON_AddStringToObject(rootdata,"FAULT_LOCATION","");cJSON_AddStringToObject(rootdata,"REWORK_REP_TIMES","");cJSON_AddStringToObject(rootdata,"ABILITY","");cJSON_AddStringToObject(rootdata,"PROCESSING_METHOD","");cJSON_AddStringToObject(rootdata,"TESTER_CODE","");cJSON_AddStringToObject(rootdata,"MAINTENANCE_PER_CODE","");cJSON_AddStringToObject(rootdata,"STATE","");cJSON_AddStringToObject(rootdata,"INPUT_TIME","");cJSON_AddStringToObject(rootdata,"COMPLEITION_TIME","");cJSON_AddStringToObject(rootdata,"MAINT_DETAILS","");*///QString qstrmain="";QString qstrmini="";QString str ="";QString strmini ="";QMessageBox::warning(this,tr("Warning"),qstrmain);char main[50]={0};QByteArray ba = qstrmain.toLocal8Bit();memcpy(main,ba.data(),ba.size()+1);cJSON_AddStringToObject(rootdata,"FAULT_CLASS",main);char mini[50]={0};ba = qstrmini.toLocal8Bit();memcpy(mini,ba.data(),ba.size()+1);cJSON_AddStringToObject(rootdata,"FAULT_CAUSE",mini);int aa=0;FuWuQiData fad;char senddata[1024]={0};//memcpy(senddata,);char *jsonBuf=cJSON_PrintUnformatted(rootdata);char outBuf[1024]={0x00};int outlen=0;int iErrCode=-1;QMessageBox::warning(this,tr("Warning"),tr("開始發數據"));int result = g_minipaydllFunction->m_ShouHouInforToSQL(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);if(iErrCode==0){QMessageBox::warning(this,tr("Warning"),tr("數據發完"));}return; }void ShouHouTool::mousePressEvent ( QMouseEvent * event ) {//QMessageBox::warning(this,tr("Warning"),tr("鼠標操作")); } void ShouHouTool::getPadIds() {QMessageBox::warning(this,tr("Warning"),tr("父類調用成功")); }void ShouHouTool::onbutaddtoDetailInformation() {char outValue[2048]={0x00};byte outTemp[512]={0x00};int iErrCode=-1;int outlen=0;cJSON *MBSInformation;cJSON *arrayItem;MBSInformation=cJSON_CreateObject();cJSON_AddStringToObject(MBSInformation,"SERIAL_NO","0000290220068442");cJSON_AddStringToObject(MBSInformation,"Position_number","");cJSON_AddStringToObject(MBSInformation,"MIDDLE_CODE","");cJSON_AddStringToObject(MBSInformation,"TOOLS_INFO" ,"");cJSON_AddStringToObject(MBSInformation,"TOOLS_ALIAS" ,"");char *jsonBuf=cJSON_PrintUnformatted(MBSInformation);int result=g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outValue,outlen,iErrCode);if(result==STATUS_OK){ShouHouWeiXiuDetailDeal( outValue,outlen,iErrCode);}else{ui.textEditInfor->setText("獲取服務器數據失敗");}cJSON_Delete(MBSInformation);return ; }int ShouHouTool::ShouHouWeiXiuDeal( char *VerBuf,int vsize,char *outBuf,int &outlen,LISTINTVector &listvector) {char outValue[2048]={0x00};char outTemp[512]={0x00};QString strTemp=""; listvector.clear();int olen=0;int nlen=0; char*MySQLConnet=("服務器連接異常"); cJSON *MBSInformation;cJSON *object;MBSInformation=cJSON_CreateObject(); if (outValue[0] ==0x00){ outlen=0x00;nlen = ((VerBuf[1] << 8) & 0xFF00);nlen |= VerBuf[2] & 0xFF; memcpy(outTemp,VerBuf+3,nlen);MBSInformation=cJSON_Parse((char *)outTemp); cJSON *arrayItem = cJSON_GetObjectItem(MBSInformation,"FAULT_CODE");char data[1024]={0};if (arrayItem >0){strTemp =arrayItem->valuestring; int inum=cJSON_GetArraySize(arrayItem);cJSON*item;for(int i=0;i<inum;i++) {FuWuQiData fw;memset(fw.datafwq,0x00,sizeof(fw.datafwq));object=cJSON_GetArrayItem(arrayItem,i);item=cJSON_GetObjectItem(object,"id");memcpy((char*)(LPCTSTR)fw.id,item->valuestring,strlen(item->valuestring));item=cJSON_GetObjectItem(object,"text");memcpy((char*)(LPCTSTR)fw.datafwq,item->valuestring,strlen(item->valuestring)); listvector.push_back(fw);}}} cJSON_Delete(MBSInformation);return 0; }void ShouHouTool::startThread() {DWORD m_dwOpThreadID; //線程IDHANDLE m_hOpThread; //發送線程句柄m_hOpThread = CreateThread(NULL,0,ReadVersion,this,0,&m_dwOpThreadID);}DWORD WINAPI ShouHouTool::ReadVersion(LPVOID pParam) {ShouHouTool* dlg = (ShouHouTool*)pParam;dlg->onbutaddtoDetailInformation();return 0; }int ShouHouTool::ShouHouWeiXiuDetailDeal( char *VerBuf,int vsize,int iEEcode) {char outValue[2048]={0x00};char outTemp[1024]={0x00};QString strTemp=""; int olen=0;int nlen=0; QString strid="",strFAC_ID="",strMIDDLE_CODE="";QString strSERIAL_NO="",strFAULT_CLASS="", strFAULT_CAUSE="",strRETEST_FAILURE="";QString strFAULT_NUM="",strFAULT_LOCATION="", strREWORK_REP_TIMES="",strABILITY=""; QString strPROCESSING_METHOD="",strTESTER_CODE="",strMAINTENANCE_PER_CODE="",strSTATE="",strINPUT_TIME="",strCOMPLEITION_TIME="";QString strMAINT_DETAILS="", strCREATE_USER_NAME="",strCREATE_DATE_TIME="",strUPDATE_USER_NAME="",strUPDATE_DATE_TIME="";cJSON *MBSInformation,*arrayItem;MBSInformation=cJSON_CreateObject(); if (VerBuf[0] ==0x00 && olen > 0){ nlen = ((VerBuf[1] << 8) & 0xFF00);nlen |= VerBuf[2] & 0xFF; memcpy(outTemp,VerBuf+3,nlen);if (nlen >0){MBSInformation=cJSON_Parse((char *)outTemp); arrayItem = cJSON_GetObjectItem(MBSInformation,"ID");if (arrayItem >0){strid =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"FAC_ID");if (arrayItem >0){strFAC_ID =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"MIDDLE_CODE");if (arrayItem >0){strMIDDLE_CODE =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"SERIAL_NO");if (arrayItem >0){strSERIAL_NO =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CLASS");if (arrayItem >0){strFAULT_CLASS =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CAUSE");if (arrayItem >0){strFAULT_CAUSE =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"RETEST_FAILURE");if (arrayItem >0){strRETEST_FAILURE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_NUM");if (arrayItem >0){strFAULT_NUM =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_LOCATION");if (arrayItem >0){strFAULT_LOCATION =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"REWORK_REP_TIMES");if (arrayItem >0){strREWORK_REP_TIMES =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"ABILITY");if (arrayItem >0){strABILITY =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"PROCESSING_METHOD");if (arrayItem >0){strPROCESSING_METHOD =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"TESTER_CODE");if (arrayItem >0){strTESTER_CODE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINTENANCE_PER_CODE");if (arrayItem >0){strMAINTENANCE_PER_CODE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"STATE");if (arrayItem >0){strSTATE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"INPUT_TIME");if (arrayItem >0){strINPUT_TIME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"COMPLEITION_TIME");if (arrayItem >0){strCOMPLEITION_TIME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINT_DETAILS");if (arrayItem >0){strMAINT_DETAILS =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_USER_NAME");if (arrayItem >0){strCREATE_USER_NAME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_DATE_TIME");if (arrayItem >0){strCREATE_DATE_TIME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_USER_NAME");if (arrayItem >0){strUPDATE_USER_NAME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_DATE_TIME");if (arrayItem >0){strUPDATE_DATE_TIME =arrayItem->valuestring;}// strTemp =strMIDDLE_CODE+"|"+strSERIAL_NO+"|"+strFAULT_CLASS+"|"+strFAULT_CAUSE+"|"+strRETEST_FAILURE+"|"+strFAULT_NUM+"|"+strFAULT_LOCATION+"|"+strREWORK_REP_TIMES+"|"+strABILITY+"|"+strPROCESSING_METHOD+"|"+strTESTER_CODE+"|"+strMAINTENANCE_PER_CODE+"|"+strINPUT_TIME+"|"+strCOMPLEITION_TIME+"|"+strMAINT_DETAILS+"|"+strCREATE_USER_NAME+"|"+strCREATE_DATE_TIME+"|"+strUPDATE_USER_NAME+"|"+strUPDATE_DATE_TIME;ui.textEditInfor->setText(strTemp);}else{///ui.textEditInfor->setText("無法解析到數據");} }else { nlen = ((VerBuf[1] << 8) & 0xFF00);nlen |= VerBuf[2] & 0xFF; memcpy(outTemp,VerBuf+3,nlen);MBSInformation=cJSON_Parse((char *)outTemp); arrayItem =cJSON_GetObjectItem (MBSInformation,"msg");if (arrayItem >0){strTemp =arrayItem->valuestring;}ui.textEditInfor->setText(strTemp);} cJSON_Delete(MBSInformation);return 0; }int ShouHouTool::GetShouHouWeiXiuRecord( char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode) {char outValue[2048]={0x00};byte outTemp[512]={0x00};QString strTemp=""; QString strid="",strFAC_ID="",strMIDDLE_CODE="";QString strSERIAL_NO="",strFAULT_CLASS="", strFAULT_CAUSE="",strRETEST_FAILURE="";QString strFAULT_NUM="",strFAULT_LOCATION="", strREWORK_REP_TIMES="",strABILITY=""; QString strPROCESSING_METHOD="",strTESTER_CODE="",strMAINTENANCE_PER_CODE="",strSTATE="",strINPUT_TIME="",strCOMPLEITION_TIME="";QString strMAINT_DETAILS="", strCREATE_USER_NAME="",strCREATE_DATE_TIME="",strUPDATE_USER_NAME="",strUPDATE_DATE_TIME="";cJSON *MBSInformation;cJSON *arrayItem;MBSInformation=cJSON_CreateObject();cJSON_AddStringToObject(MBSInformation,"TUSN","");cJSON_AddStringToObject(MBSInformation,"Position_number","");cJSON_AddStringToObject(MBSInformation,"order_number","");cJSON_AddStringToObject(MBSInformation,"TOOLS_INFO" ,"");cJSON_AddStringToObject(MBSInformation,"TOOLS_ALIAS" ,"");char *jsonBuf=cJSON_PrintUnformatted(MBSInformation);g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);int olen=0;int nlen=0; char*MySQLConnet=("服務器連接異常"); g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);iErrCode=VerBuf[0]&0xff;if (VerBuf[0] ==0x00 && olen > 0){ nlen = ((VerBuf[1] << 8) & 0xFF00);nlen |= VerBuf[2] & 0xFF; memcpy(outTemp,VerBuf+3,nlen);if (nlen >0){MBSInformation=cJSON_Parse((char *)outTemp); cJSON* arrayItem = cJSON_GetObjectItem(MBSInformation,"ID");if (arrayItem >0){strid =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"FAC_ID");if (arrayItem >0){strFAC_ID =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"MIDDLE_CODE");if (arrayItem >0){strMIDDLE_CODE =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"SERIAL_NO");if (arrayItem >0){strSERIAL_NO =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CLASS");if (arrayItem >0){strFAULT_CLASS =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CAUSE");if (arrayItem >0){strFAULT_CAUSE =arrayItem->valuestring;}///arrayItem =cJSON_GetObjectItem (MBSInformation,"RETEST_FAILURE");if (arrayItem >0){strRETEST_FAILURE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_NUM");if (arrayItem >0){strFAULT_NUM =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_LOCATION");if (arrayItem >0){strFAULT_LOCATION =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"REWORK_REP_TIMES");if (arrayItem >0){strREWORK_REP_TIMES =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"ABILITY");if (arrayItem >0){strABILITY =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"PROCESSING_METHOD");if (arrayItem >0){strPROCESSING_METHOD =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"TESTER_CODE");if (arrayItem >0){strTESTER_CODE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINTENANCE_PER_CODE");if (arrayItem >0){strMAINTENANCE_PER_CODE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"STATE");if (arrayItem >0){strSTATE =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"INPUT_TIME");if (arrayItem >0){strINPUT_TIME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"COMPLEITION_TIME");if (arrayItem >0){strCOMPLEITION_TIME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINT_DETAILS");if (arrayItem >0){strMAINT_DETAILS =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_USER_NAME");if (arrayItem >0){strCREATE_USER_NAME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_DATE_TIME");if (arrayItem >0){strCREATE_DATE_TIME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_USER_NAME");if (arrayItem >0){strUPDATE_USER_NAME =arrayItem->valuestring;}arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_DATE_TIME");if (arrayItem >0){strUPDATE_DATE_TIME =arrayItem->valuestring;}// strTemp =strMIDDLE_CODE+"|"+strSERIAL_NO+"|"+strFAULT_CLASS+"|"+strFAULT_CAUSE+"|"+strRETEST_FAILURE+"|"+strFAULT_NUM+"|"+strFAULT_LOCATION+"|"+strREWORK_REP_TIMES+"|"+strABILITY+"|"+strPROCESSING_METHOD+"|"+strTESTER_CODE+"|"+strMAINTENANCE_PER_CODE+"|"+strINPUT_TIME+"|"+strCOMPLEITION_TIME+"|"+strMAINT_DETAILS+"|"+strCREATE_USER_NAME+"|"+strCREATE_DATE_TIME+"|"+strUPDATE_USER_NAME+"|"+strUPDATE_DATE_TIME;ui.textEditInfor->setText(strTemp);}else{///nlen = ((outValue[1] << 8) & 0xFF00);nlen |= outValue[2] & 0xFF; memcpy(outTemp,outValue+3,nlen);MBSInformation=cJSON_Parse((char *)outTemp); arrayItem =cJSON_GetObjectItem (MBSInformation,"msg");if (arrayItem >0){strTemp =arrayItem->valuestring;}ui.textEditInfor->setText(strTemp);} }else { iErrCode =-1;memcpy((char*)outBuf,MySQLConnet,strlen(MySQLConnet));} cJSON_Delete(MBSInformation);return 0; }總結
以上是生活随笔為你收集整理的cjson调用的实例 c++的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++程序员会用到的函数积累
- 下一篇: 学习路径