之前在網上看到使用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串