欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

JsonCpp第三課生成json格式

1)數(shù)據(jù)內(nèi)嵌json
{
? "code" : "SheBeiLiXianGaoJingShangChuan",
? "params" :
?{
???? "alarm_source" : "192.68.1.0",
???? "id" : "234",
???? "remark" : "fire alarm",
???? "time_alarm" : "2017-2-1 21:34:21"
?? }
}

成都創(chuàng)新互聯(lián)公司2013年成立,先為北林等服務(wù)建站,北林等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為北林企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

Json::Value jsonCode;
jsonCode["code"] ="SheBeiLiXianGaoJingShangChuan";
?
Json::Value jsonParams;
jsonParams["id"] ="234";
jsonParams["remark"] = "firealarm";
jsonParams["time_alarm"] ="2017-2-1 21:34:21";
jsonParams["alarm_source"] ="192.68.1.0";
?
jsonCode["params"] = jsonParams;


2)數(shù)據(jù)內(nèi)嵌字符串?dāng)?shù)組
{
??? "extra_fields":[
??????? "custom_field_1",
??????? "custom_field_2"
?? ],
??? "surveillance_ids":[
??????? "0"
??? ],
??? "order":{
??????? "timestamp":-1
??? },
??? "hit_condition":{
??????? "hit_similarity":80
??? },
??? "start":0,
??? "limit":100
}
代碼
?Json::Value root;
?Json::Value jsonExtraFields;
?jsonExtraFields.append("custom_field_1");
?jsonExtraFields.append("custom_field_2");
?root["extra_fileds"] = jsonExtraFields;
?Json::Value jsonSurveillanceIds;
?jsonSurveillanceIds.append("0");
?root["surveillance_ids"] = jsonSurveillanceIds;
?Json::Value jsonTimestamp;
?jsonTimestamp["timestamp"] = -1;
?root["order"] = jsonTimestamp;
?Json::Value jsonHitSimilarity;
?jsonHitSimilarity["hit_similarity"] = 80;
?root["hit_condition"] = jsonHitSimilarity;
?root["start"] = 0;
?root["limit"] = 100;
?std::string strResult = root.toStyledString();

3)創(chuàng)建一個(gè)標(biāo)準(zhǔn)帶有縮進(jìn)格式的json文件

void WriteContentToJsonFile()
{
?Json::Value root;
?for (int i = 0; i < 10; i++)
?{
? Json::Value node;
? node["zoom"] = 1;
? root["data"].append(node);
?}
?cout << "直接輸出:" << endl;
?Json::FastWriter fw;
?cout << fw.write(root) << endl ;
//直接輸出的沒有進(jìn)行換行,查看困難

?cout << "縮進(jìn)輸出:" << endl;
?Json::StyledWriter sw;
?cout << sw.write(root) << endl ;
?ofstream ofstreamHandle;
?ofstreamHandle.open("fengyuzaitu51cto.json");
?ofstreamHandle << sw.write(root);
?ofstreamHandle.close();
}

注意事項(xiàng)

????Json::Value valueNodeList;

? ? for(int i=0; i <3; i++)

{

????Json::Value nodeChannel;

????nodeChannel["id"] = i;

????valueNodeList.append(nodeChannel);

}

?Json::Value valueRoot;

?std::cout<<valueNodeList.size()<<std::endl;\\輸出3

?valueRoot["channel"] = valueNodeList;

std::cout<<valueNodeList.size()<<std::endl;\\輸出0

進(jìn)行如上的賦值操作之后,不能再調(diào)用valueNodeList訪問數(shù)組,例如調(diào)用valueNodeList.size訪問到的數(shù)據(jù)始終返回0,因?yàn)閿?shù)據(jù)已經(jīng)遷移到valueRoot對(duì)象中。

????

當(dāng)前文章:JsonCpp第三課生成json格式
本文鏈接:http://www.chinadenli.net/article10/jdjigo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作做網(wǎng)站Google云服務(wù)器自適應(yīng)網(wǎng)站網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)