C++解析json格式文本移植第三方库jsoncpp[缺源码解析]
发布日期:2021-06-29 11:09:10
浏览次数:2
分类:技术文章
本文共 3102 字,大约阅读时间需要 10 分钟。
一;’移植第三方库
下载第三方库源码网站 https://sourceforge.net/projects/jsoncpp/编译第三方库的静态lib
https://www.cnblogs.com/arxive/p/11220854.html注意链接时要与生成是的格式形式一致这里都是多线程的MDT链接
https://blog.csdn.net/chenxun_2010/article/details/41847131编译的时候还注意包含include的时候采用""容易编过,
二;使用第三方库API
1、解析json文件解析的json文件{ "name": "BeJson", "url": "http://www.bejson.com", "page": 88, "isNonProfit": true, "address": { "C1":{ "street": "科技园路.", "IP":"123" }, "C2":{ "street": "江苏苏州.", "IP":"1234" }, "C3":{ "street": "中国.", "IP":"12345" } }, "links": [ { "name": "Google", "url": "http://www.google.com" }, { "name": "Baidu", "url": "http://www.baidu.com" }, { "name": "SoSo", "url": "http://www.SoSo.com" } ]}
解析核心代码Json::Reader reader; Json::Value root; int nRole = 0; string strname; string strurl; int ipage; bool bisNonProfit; vectorvc_strMemerName; // 解析json内容 if (reader.parse(is, root)) { strname = root["name"].asString(); strurl = root["url"].asString(); ipage = root["page"].asInt(); bisNonProfit = root["isNonProfit"].asBool(); cout << "name:" << strname << endl; cout << "url:" << strurl << endl; cout << "page:" << ipage << endl; cout << "isNonProfit:" << bisNonProfit << endl; Json::Value Obj_address; bool b_isAddressObj = root.isMember("address");//遍历对象组合 if (b_isAddressObj) { int i_size = root["address"].size(); vc_strMemerName = root["address"].getMemberNames(); for (int i = 0; i < vc_strMemerName.size(); i++) { cout << vc_strMemerName[i] << ":" << root["address"][vc_strMemerName[i]]["street"].asString() << endl; cout << vc_strMemerName[i] << ":" << root["address"][vc_strMemerName[i]]["IP"].asString() << endl; } } if (root["links"].isArray())//遍历数组是对象的组合 { int i_size = root["links"].size(); for (int i = 0; i < i_size; i++) { cout << root["links"][i]["name"].asString() << endl; cout << root["links"][i]["url"].asString() << endl; } } } is.close();
2、递归解析菜单库,输出菜单层级
其格式为有部分对象节点中包含children数组节点(其中包含多个对象,而对象里面又可以包含children数组)大致为很多children这种类型,提取出children子菜单的菜单层级表{ "data": { "jsonMenu": { "id":"123", "displayName":"zw", "Type":"P", "children": [ { "id":"1233", "displayName":"z2w", "Type":"P1", "children": [ ] }, { "id":"12335", "displayName":"z2w2", "Type":"P13", "children": [ { "id":"12336", "displayName":"z2w42", "Type":"P13234", "children": [ ] }, { "id":"1233ss6", "displayName":"z2w4sd2", "Type":"P13qwew234", "children": [ "id":"1s6", "displayName":"w4sd2", "Type":"P134", "children": [ ] ] } ] } ] } }}三;jsonCpp源码学习(如果解析出json文件数组进行存储到root中来让我们提取的) 等C++课程第三部分看完,及时填充上,以及解析XML格式文件和其源码
转载地址:https://blog.csdn.net/zw1996/article/details/108249996 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月12日 17时38分22秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
中国信息化发展八大趋势(四)
2019-04-29
电商大战二十年
2019-04-29
神奇的麦考林
2019-04-29
centos7使用rpm安装mysql遇到的error: Failed dependencies: mysql-community-common(x86-64) 5.7.9 is needed
2019-04-29
spark报错:warn util.utils::service ‘sparkUI‘ can not bind on part 4040.Attempting port 4041.4042等错误
2019-04-29
Error getting authority: Error initializing authority: Could not connect: No such file or directory
2019-04-29
编程程软件测试思维方式:如何科学制定测试计划
2019-04-29
BLE蓝牙4.0串口调试助手
2019-04-29
树莓派WIFI设置
2019-04-29
用vcgencmd获取树莓派硬件状态数据
2019-04-29
IIS 多域名多张证书配置
2019-04-29
树莓派LINUX 截屏
2019-04-29
树莓派Raspberry Pi的嵌入式QT平台
2019-04-29
apache https
2019-04-29
Debian Jessie安装支持HTML5音视频的Chromium浏览器听百度音乐
2019-04-29
nanopi2 启动信息
2019-04-29
POS打印机驱动大全
2019-04-29
phpstudy https
2019-04-29
centos apache 最新版HTTPS配置
2019-04-29