精品网站免费,宜昌建网站,长春财经学院占地面积,wordpress相册模式选择目录
一、读数据 1、简单对象读取
2、数组读取
3、对象读取
二、写数据
1、简单生成JSON
2、对象数组JSON
3、嵌套对象
三、一个综合例子
1、读JSON
2、写JSON 一、读数据 1、简单对象读取
{app: xnwVideo,src: C:\\buil…
目录
一、读数据 1、简单对象读取
2、数组读取
3、对象读取
二、写数据
1、简单生成JSON
2、对象数组JSON
3、嵌套对象
三、一个综合例子
1、读JSON
2、写JSON 一、读数据 1、简单对象读取
{app: xnwVideo,src: C:\\build-video\\Output,dest: C:\\build-video\\1.0.32,version: 1.0.32,build: 32,note: 布局json读取,act: All
} CBinBuf buf;buf.ReadFile(jsonInfo.json);CJsonObj json(buf);CBinBuf app, src, des, note, build, fullVersion, act;json.getString(app, app);json.getString(src, src);json.getString(dest, des);json.getString(note, note);json.getString(build, build);json.getString(version, fullVersion);json.getString(act, act); 2、数组读取
文件如下
[{id: Integrated Webcam:\\\\?\\usb#22vid_0c45pid_671fmi_00#2268c5ffc600000#22{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global,res: 1280x720},{id: XSplit VCam:\\\\?\\root#22image#220000#22{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global,res: 1280x720},{id: YY开播:,res: 1280x720},{id: c922 Pro Stream Webcam:\\\\?\\usb#22vid_046dpid_085cmi_00#2271e59b99a00000#22{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global,res: 1920x1080}
] 读取方式 std::mapstd::string, std::string camIDResMap_;CBinBuf buf;buf.ReadFile(jsonPath.c_str());CJsonObj json(buf);for (int i 0; i json.get_arry_size(); i){CJsonObj * pJson json.get_arry_at(i);string id, res;pJson-getString(id, id);pJson-getString(res, res);camIDResMap_[id] res;}类似的还有 for (int i 0; i class_info-get_arry_size(); i) {CJsonObj* pJson class_info-get_arry_at(i);std::string courseID, chapterID, qID, chapterName, startTime, endTime, className, imgUrl;int nStatus;pJson-getString(course.id, courseID);pJson-getString(id, chapterID); pJson-getString(class.qid, qID);pJson-getString(name, chapterName);pJson-getString(start_time, startTime);pJson-getString(end_time, endTime);nStatus pJson-getInt(live_status);/*CJsonObj* pCourseJson pJson-getObj(course, err);pCourseJson-getString(name, className); pCourseJson-getString(cover_url, imgUrl);*/pJson-getString(course.name, className);pJson-getString(course.cover_url, imgUrl);//timelong iStartTime atoi(startTime.c_str());long iEndTime atoi(endTime.c_str());std::string timeStr GetTimeStr(iStartTime, iEndTime);//添加列表中ui::ListContainerElement* pItem dynamic_castui::ListContainerElement*(ui::GlobalManager::CreateBoxWithCache(LmyClass/myclass_list_item.xml));myClass_list-Add(pItem);if (curCourseIdcourseIDcurChapterIdchapterID){m_pCurItem pItem; //刷新后重置当前节点bCurItemReseted TRUE;}//详细信息设置SetText(pItem, LcourseName, nbase::UTF8ToUTF16(className).c_str());SetText(pItem, LchapterName, nbase::UTF8ToUTF16(chapterName).c_str());SetText(pItem, Ltime, MyString::stows(timeStr).c_str());//asic-utfSetDataID(pItem, Ltime, startTime);SetDataID(pItem, LcourseName, endTime); //此项利用上保存这节课结束时间std::wstring statusStr;switch (nStatus){case 0:statusStr L未开始;break;case 1:statusStr L正在直播;break;case 4:statusStr L正在直播;break;case 2:statusStr L已结束;break;case 3:statusStr L缺课;break;}SetText(pItem, Llive_status, statusStr);ui::Control* pClassPhoto (ui::Control*)pItem-FindSubControl(LclassPhoto);if (pClassPhoto){//根据Json 传来的照片网址与本地地址映射//之所以加?做分隔符是因为文件名不能包含?std::wstring url nbase::UTF8ToUTF16(imgUrl);//此段代码用于线程下载时使用std::wstring IndexStr std::to_wstring(i);std::wstring pathTemp MyString::format(Ltmp\\classPhoto%s.png, IndexStr.c_str());std::wstring localPath IndexStr L? localFoldPathW pathTemp;std::wstring remotePath IndexStr L| url;AddMapItem(remotePath, localPath);///xnw_http_download(imgUrl.c_str(), GetHWND(), i);}ui::Button* pEnterLSRoomBtn (ui::Button*)pItem-FindSubControl(LenterLiveRoom_Btn); pEnterLSRoomBtn-AttachClick(nbase::Bind(MyClassForm::EnterRoom, this, std::placeholders::_1));pItem-SetUTF8DataID(courseID); //设置item标识为章节IDpEnterLSRoomBtn-SetUTF8DataID(chapterID);pClassPhoto-SetUTF8DataID(qID);}if (!bCurItemReseted){m_pCurItem NULL;}}
3、对象读取
{list: [{name: 亮度92,props: {BacklightCompensation: 1,Brightness: 92,ColorEnable: 16,Contrast: 91,Gain: 16,Gamma: 62,Hue: 91,Saturation: 255,Sharpness: 62,WhiteBalance: -1},control: {Exposure: -4,Focus: 0,Iris: 100,Pan: 0,Roll: 0,Tilt: 0,Zoom: 100}},{name: 高亮170,props: {BacklightCompensation: 0,Brightness: 170,ColorEnable: 3,Contrast: 128,Gain: 3,Gamma: 188,Hue: 128,Saturation: 128,Sharpness: 188,WhiteBalance: -1},control: {Exposure: -4,Focus: 0,Iris: 100,Pan: 0,Roll: 0,Tilt: 0,Zoom: 100}}]
} 对象的值又是数组的情况下读取方式 CJsonObj ampJson(jsonS.c_str());{int nCount 0;int err;CJsonObj* arry ampJson.getObj(list, err);if (arry arry-isarray()) {nCount arry-get_arry_size();std::string s;std::wstring name;for (int i 0; i arry-get_arry_size(); i) {CJsonObj* pJson arry-get_arry_at(i);pJson-getString(name, s);name to_wchar_t(s);g_SelfCamAmpPropNameVec.push_back(name);}}} 类似的还有 CBinBuf bfJson;if(bfJson.ReadFile(m_file)) {load(bfJson, 0); void load(const char* jstr, int merge) {uint32_t now (uint32_t)time(0);CJsonObj js(jstr);m_tm js.getInt(tm, 0);m_tmReport js.getInt(tmReport, now);int err;CJsonObj* pList js.getObj(list, err);if(pList) {std::vectorCDNINFO v, vOld;if(merge) {for(int i0; im_vCdn.size(); i) vOld.push_back(m_vCdn[i]);}m_vCdn.clear();for(int i0; ipList-get_arry_size(); i) {CDNINFO c;CJsonObj* pItem pList-get_arry_at(i);c.from(pItem);add(c, merge, vOld);}}} 二、写数据 1、简单生成JSON CJsonString bf({);bf.append_item(file, szUtf8);bf.append_item(url, cbitem-url);bf.append_item(wparam,(uint64_t)cbitem-wParam);bf.close(}); 又如
void MakeDefaultJson(CJsonString jsonStr){jsonStr.append_item(is_beauty_on, 1); //美颜全局开关0为关1为开默认为1//滤镜 jsonStr.append_item(filter_level, 0); //0-10 -[0,1] 取值范围 0.0-1.0,0.0为无效果1.0为最大效果默认值1.0jsonStr.append_item(filter_name, origin);//美白jsonStr.append_item(color_level, 2); //0-20 [0,2.0] 取值范围 0.0-2.0,0.0为无效果2.0为最大效果默认值0.2//红润jsonStr.append_item(red_level, 5); //0-20 [0,2.0] 取值范围 0.0-2.0,0.0为无效果2.0为最大效果默认值0.5//磨皮程度jsonStr.append_item(blur_level, 60); //[0,6.0] 磨皮程度取值范围0.0-6.0默认6.0jsonStr.append_item(skin_detect, 0); //肤色检测开关0为关1为开 默认0jsonStr.append_item(nonskin_blur_scale, 0); //0-10 [0,1]肤色检测之后非肤色区域的融合程度取值范围0.0-1.0默认0.0jsonStr.append_item(heavy_blur, 0); //朦胧磨皮开关0为清晰磨皮1为朦胧磨皮jsonStr.append_item(blur_type, 2); //此参数优先级比heavy_blur低在使用时要将heavy_blur设为00 清晰磨皮 1 朦胧磨皮 2精细磨皮jsonStr.append_item(blur_use_mask, 0); //ios端默认为1其他端默认为0。1为开启基于人脸的磨皮mask0为不使用mask正常磨皮。只在blur_type为2时生效。jsonStr.append_item(sharpen, 2); //锐化程度取值范围0.0-1.0默认0.2jsonStr.close();//jsonStr.WriteFile(jsonInfoRes.json);
} 2、对象数组JSON CJsonString jsonStr;jsonStr.begin([);for (auto it : camIDResMap){CJsonString camJson;camJson.begin({);camJson.append_item(id, it.first.c_str());camJson.append_item(res, it.second.c_str());camJson.close(});jsonStr.append_obj(camJson);}jsonStr.close(]);jsonStr.WriteFile(m_camjsonPath); 3、嵌套对象 {list: [{name: 亮度92,props: {BacklightCompensation: 1,Brightness: 92},control: {Exposure: -4,Zoom: 100}},{name: 高亮170,props: {BacklightCompensation: 0,WhiteBalance: -1},control: {Exposure: -4,Zoom: 100}}]
} CJsonString jsonStr;jsonStr.begin([);int nCount 0;for (auto it : selfCamPros_){std::mapstd::string, int ampMap it.second;std::wstring nameW it.first;std::mapstd::string, int ctlMap selfCamControls_[nameW];std::string name to_string(nameW);CJsonString camAllJson;camAllJson.begin({);camAllJson.append_item(name, name.c_str());CJsonString ampJsonObj;ampJsonObj.begin({);auto oneAmpIt ampMap.begin();while (oneAmpIt ! ampMap.end()){ampJsonObj.append_item(oneAmpIt-first.c_str(), oneAmpIt-second);oneAmpIt;}ampJsonObj.close(});camAllJson.append_obj(props, ampJsonObj);CJsonString ctlJsonObj;ctlJsonObj.begin({);auto oneCtlIt ctlMap.begin();while (oneCtlIt ! ctlMap.end()){ctlJsonObj.append_item(oneCtlIt-first.c_str(), oneCtlIt-second);oneCtlIt;}ctlJsonObj.close(});camAllJson.append_obj(control, ctlJsonObj);camAllJson.close(});jsonStr.append_obj(camAllJson);}jsonStr.close(]);CJsonString listObjJsonS;listObjJsonS.begin({);listObjJsonS.append_obj(list, jsonStr);listObjJsonS.close(});listObjJsonS.WriteFile(sysJsonPath); 又如 CJsonString js, list;js.append_item_u32(tm, m_tm);js.append_item_u32(tmReport, m_tmReport);format_json(list);js.append_obj(list, list);js.close(});js.WriteFile(m_file); void format_json(CJsonString js) {js.begin([);size_t n m_vCdn.size();for(int i0; in; i) {CDNINFO c m_vCdn[i];CJsonString cdn;c.format(cdn);js.append_obj(cdn);}js.close(]);} 又如 CJsonString js,list;list.begin([);for (auto it nameVec.begin(); it ! nameVec.end(); it){CJsonString jsObj;std::wstring name *it;if (name L类别)continue;std::string name8 nbase::UTF16ToUTF8(name);jsObj.begin({);jsObj.append_item(name, name8.c_str());jsObj.close(});list.append_obj(jsObj);}list.close(]);js.append_obj(list, list);js.close(});js.WriteFile(d:\\name.json); 三、一个综合例子
{nameArr: [{account: 张三},{account: 王五},{account: 李四}],phoneArr: [{account: 1800000}]
} 1、读JSON std::setstd::wstring acountSet_;std::setstd::wstring acountPhoneSet_;void ReadAcountSet()
{std::string path GetXnwAccountJsonPath();CBinBuf buf;if (buf.Read(path.c_str())){CJsonObj json(buf);int err;CJsonObj* arry json.getObj(nameArr, err);if (arry arry-isarray()){for (int i 0; i arry-get_arry_size(); i){CJsonObj * pJson arry-get_arry_at(i);std::string name;pJson-getString(account, name);if (!name.empty()){std::wstring namew nbase::UTF8ToUTF16(name);acountSet_.insert(namew);}}}arry json.getObj(phoneArr, err);if (arry arry-isarray()){for (int i 0; i arry-get_arry_size(); i){CJsonObj * pJson arry-get_arry_at(i);std::string name;pJson-getString(account, name);std::wstring namew nbase::UTF8ToUTF16(name);acountPhoneSet_.insert(namew);}}}} 2、写JSON
void SaveAcountSet(){std::string path GetXnwAccountJsonPath();CJsonString listJsonStr;listJsonStr.begin({);CJsonString jsonStr;jsonStr.begin([);for (auto it : acountSet_){std::string name nbase::UTF16ToUTF8(it);CJsonString json;json.begin({);json.append_item(account, name.c_str());json.close(});jsonStr.append_obj(json);}jsonStr.close(]);listJsonStr.append_obj(nameArr, jsonStr);CJsonString jsonStr2;jsonStr2.begin([);for (auto it : acountPhoneSet_){std::string name nbase::UTF16ToUTF8(it);CJsonString json;json.begin({);json.append_item(account, name.c_str());json.close(});jsonStr2.append_obj(json);}jsonStr2.close(]);listJsonStr.append_obj(phoneArr, jsonStr2);listJsonStr.close(});listJsonStr.WriteFile(path.c_str());
} 文章转载自: http://www.morning.rqrxh.cn.gov.cn.rqrxh.cn http://www.morning.wcrcy.cn.gov.cn.wcrcy.cn http://www.morning.sjpbh.cn.gov.cn.sjpbh.cn http://www.morning.dbphz.cn.gov.cn.dbphz.cn http://www.morning.qtqk.cn.gov.cn.qtqk.cn http://www.morning.gzttoyp.com.gov.cn.gzttoyp.com http://www.morning.kjlia.com.gov.cn.kjlia.com http://www.morning.qyrnp.cn.gov.cn.qyrnp.cn http://www.morning.byrlg.cn.gov.cn.byrlg.cn http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn http://www.morning.xhgcr.cn.gov.cn.xhgcr.cn http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.cgstn.cn.gov.cn.cgstn.cn http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn http://www.morning.frpm.cn.gov.cn.frpm.cn http://www.morning.xqcgb.cn.gov.cn.xqcgb.cn http://www.morning.zpyh.cn.gov.cn.zpyh.cn http://www.morning.xtqld.cn.gov.cn.xtqld.cn http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn http://www.morning.lhyhx.cn.gov.cn.lhyhx.cn http://www.morning.nrtpb.cn.gov.cn.nrtpb.cn http://www.morning.mgzjz.cn.gov.cn.mgzjz.cn http://www.morning.nqbs.cn.gov.cn.nqbs.cn http://www.morning.rljr.cn.gov.cn.rljr.cn http://www.morning.pqwhk.cn.gov.cn.pqwhk.cn http://www.morning.gbkkt.cn.gov.cn.gbkkt.cn http://www.morning.nrmyj.cn.gov.cn.nrmyj.cn http://www.morning.zlnf.cn.gov.cn.zlnf.cn http://www.morning.zjrnq.cn.gov.cn.zjrnq.cn http://www.morning.kzyr.cn.gov.cn.kzyr.cn http://www.morning.kqzrt.cn.gov.cn.kqzrt.cn http://www.morning.kmqms.cn.gov.cn.kmqms.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.fnczn.cn.gov.cn.fnczn.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.mglqf.cn.gov.cn.mglqf.cn http://www.morning.pxwzk.cn.gov.cn.pxwzk.cn http://www.morning.rymb.cn.gov.cn.rymb.cn http://www.morning.gnwse.com.gov.cn.gnwse.com http://www.morning.trqhd.cn.gov.cn.trqhd.cn http://www.morning.jqtb.cn.gov.cn.jqtb.cn http://www.morning.zmlnp.cn.gov.cn.zmlnp.cn http://www.morning.mnbcj.cn.gov.cn.mnbcj.cn http://www.morning.tqjks.cn.gov.cn.tqjks.cn http://www.morning.mxdiy.com.gov.cn.mxdiy.com http://www.morning.zdkzj.cn.gov.cn.zdkzj.cn http://www.morning.rkfwr.cn.gov.cn.rkfwr.cn http://www.morning.cykqb.cn.gov.cn.cykqb.cn http://www.morning.mdwb.cn.gov.cn.mdwb.cn http://www.morning.rkbly.cn.gov.cn.rkbly.cn http://www.morning.wqbbc.cn.gov.cn.wqbbc.cn http://www.morning.kmqwp.cn.gov.cn.kmqwp.cn http://www.morning.webpapua.com.gov.cn.webpapua.com http://www.morning.sdhmn.cn.gov.cn.sdhmn.cn http://www.morning.qphdp.cn.gov.cn.qphdp.cn http://www.morning.rmdwp.cn.gov.cn.rmdwp.cn http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn http://www.morning.rnzbr.cn.gov.cn.rnzbr.cn http://www.morning.wrlcy.cn.gov.cn.wrlcy.cn http://www.morning.ztqj.cn.gov.cn.ztqj.cn http://www.morning.fktlg.cn.gov.cn.fktlg.cn http://www.morning.zqdhr.cn.gov.cn.zqdhr.cn http://www.morning.tzjqm.cn.gov.cn.tzjqm.cn http://www.morning.qzmnr.cn.gov.cn.qzmnr.cn http://www.morning.jqswf.cn.gov.cn.jqswf.cn http://www.morning.yfrbn.cn.gov.cn.yfrbn.cn http://www.morning.llsrg.cn.gov.cn.llsrg.cn http://www.morning.ggxbyhk.cn.gov.cn.ggxbyhk.cn http://www.morning.qgfkn.cn.gov.cn.qgfkn.cn http://www.morning.ychrn.cn.gov.cn.ychrn.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.ckdgj.cn.gov.cn.ckdgj.cn http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn http://www.morning.xysdy.cn.gov.cn.xysdy.cn http://www.morning.tsnmt.cn.gov.cn.tsnmt.cn http://www.morning.zrwlz.cn.gov.cn.zrwlz.cn http://www.morning.ptysj.cn.gov.cn.ptysj.cn http://www.morning.kgslc.cn.gov.cn.kgslc.cn http://www.morning.rmxk.cn.gov.cn.rmxk.cn http://www.morning.rywr.cn.gov.cn.rywr.cn