jsoncpp用法通俗易懂之將資料合成json格式

來源:互聯網
上載者:User

標籤:

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格式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.