標籤:
void *upload(void *pParam){CUpSender *s = (CUpSender*)pParam;map<string, string> mx;char tmp[20] = {0};char filename[50] = {0};string data = "";while(1){mx.clear();FileLog(FILENAME, "in thread m_urlcount = [%d]", s->m_urlcount);while(s->m_urlcount == 0){FileLog(FILENAME, "there is no count files....wait ten seconds!!!!");sleep(10);}//這裡是將id的那部分擷取出來存入map中for(int i = 1; i != s->m_urlcount + 1; i++){memset(tmp, 0, sizeof(tmp));memset(filename, 0, sizeof(filename));snprintf(tmp, sizeof(tmp), "%d", i);snprintf(filename, sizeof(filename), "/apps/hotel/run_env/bin/id/%d", i);ifstream iis(filename);getline(iis, mx[tmp]);FileLog(FILENAME, "read urlcount from %d = %s", filename, mx[tmp].c_str());}//這裡開始組合Json::Value root;Json::Value roott; Json::Value arrayObj; Json::Value item;for(map<string, string>::iterator it = mx.begin(); it != mx.end(); it++){item["id"] = it->first;arrayObj.append(item);}roott["mac"] = s->m_strDevMac;roott["uploadfrequency"] = s->m_uploadfrequency;roott["urls"] = arrayObj;root["uwdupload"] = roott;data = root.toStyledString();FileLog(FILENAME, "the thread will send to peng webservice data : [%s], url = [%s]", data.c_str(), (s->m_threadurl).c_str());s->SendCmd1(data, s->m_threadurl);FileLog(FILENAME, "the thread sleeptime is : [%d]", s->m_threadtime);sleep(s->m_threadtime);}}
上邊是合成的過程。
{"uwdupload":{ "mac": "F0:D1:A9:C9:56:E8", "uploadfrequency": "180", "urls": [ { "id": "1", "total": "100", }, { "id": "2", "total": "50", }, { "id": "3", "total": "20", } ] }}
這是合成的結果。思想類同解析。
jsoncpp用法通俗易懂之將資料合成json格式