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
/**
*
* __ (__`\
* (__`\ \\`\
* `\\`\ \\ \
* `\\`\ \\ \
* `\\`\#\\ \#
* \_ ##\_ |##
* (___)(___)##
* (0) (0)`\##
* |~ ~ , \##
* | | \##
* | /\ \## __..---'''''-.._.._
* | | \ `\## _.--' _ `.
* Y | \ `##' \`\ \
* / | \ | `\ \
* /_...___| \ | `\\
* / `. | / ##
* | | | / ####
* | | | / ####
* | () () | \ | | _.-' ##
* `. .' `._. |______..| |-'|
* `------' | | | | | || |
* | | | | | || |
* | | | | | || |
* | | | | | || |
* _____ | | | |____| || |
* / `` |-`/ ` |` |
* \________\__\_______\__\
* """"""""" """""""'"""
* Don't be a fucking stupid donkey! No, this is a fucking mule!
*/