您现在的位置是:首页 > 文章详情

Windows10 VS2017 C++ Json解析(使用jsoncpp库)

日期:2018-12-25点击:844
版权声明:本文可能为博主原创文章,若标明出处可随便转载。 https://blog.csdn.net/Jailman/article/details/85259297

1.项目必须是win32
2.生成的lib_json.lib放到工程目录下
3.incldue的头文件放到工程目录,然后设置工程->属性->配置属性->vc++目录->包含目录
4.工程->属性->配置属性->c/c+±>代码生成->运行库,设置运行库为多线程调试 (/MTd)

首先从github下载最新版jsoncpp,0.10.7
https://github.com/open-source-parsers/jsoncpp/releases
在makefile目录的msvc2010打开工程进行编译,将库文件makefiles\msvc2010\Debug\lib_json.lib添加到工程目录,如上步骤2,然后将include目录拷贝到工程目录,按照上边步骤3设置,然后如上步骤4调整设置
解析字符串json,写码:

#include "pch.h" #include <iostream> #include <json.h> #pragma comment(lib, "lib_json.lib") using namespace std; int main() { const char* str = "{\"uploadid\": \"UP000000\",\"code\": 100,\"msg\": \"\",\"files\": \"\"}"; Json::Reader reader; Json::Value root; if (reader.parse(str, root)) // reader将Json字符串解析到root,root将包含Json里所有子元素  { std::string upload_id = root["uploadid"].asString(); // 访问节点,upload_id = "UP000000"  int code = root["code"].asInt(); // 访问节点,code = 100  cout << "upload_id: " << upload_id << endl; cout << "code: " << code << endl; } } 

在这里插入图片描述

参考文章:
http://www.cnblogs.com/liaocheng/p/4243731.html
https://blog.csdn.net/shufac/article/details/52710100

原文链接:https://yq.aliyun.com/articles/683174
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章