赞助

C++ 项目中直接使用JsonCpp源码文件

之前在网上看到使用JsonCpp都是以库的形式使用(编译源码为静态库或者动态库),这样引用很方便,但有时候报错调试看不到错误的地方,所以就想直接把源文件添加到项目中,方便调试

这是用到源码文件:

 

创建控制台工程把对应的文件导入到工程中:

 

main.cpp使用jsoncpp

#include "stdafx.h"
#include "json\json.h"

int _tmain(int argc, _TCHAR* argv[])
{

    Json::Value root;
    Json::Value arrayObj;
    Json::Value item;


    item["uid"]=Json::Value("chechenluoyang@163.com");
    item["fileName"]=Json::Value("梅西.txt");
    item["time"]=Json::Value("2017.07.28 10:55:22");
    item["type"]=Json::Value("Libcurl HTTP POST JSON");
    item["authList"]=Json::Value("test");
    arrayObj.append(item);


    root  = arrayObj;
    std::string jsonout = root.toStyledString();

    return 0;
}

编译报错:

这是因为工程默认属性是要预编译头文件,解决的办法是关掉

 

2.两种格式化json串

Demo

posted @ 2017-07-28 16:44  车臣  阅读(4772)  评论(0编辑  收藏  举报