jsoncpp在win7下用mingw编译
发布时间:2020-12-16 19:29:12 所属栏目:百科 来源:网络整理
导读:jsoncpp是一个c++封装的json包,跨平台支持windows、linux、unix等多系统。 在windows下面使用比较简单,直接往vc里面添加项目就可以了。l 如果希望用MINGW编译的库来写跨平台的一些东东的话,需要使用到README文档中的scons, scons功能和GNU make一样,又
jsoncpp是一个c++封装的json包,跨平台支持windows、linux、unix等多系统。 在windows下面使用比较简单,直接往vc里面添加项目就可以了。l 如果希望用MINGW编译的库来写跨平台的一些东东的话,需要使用到README文档中的scons, scons功能和GNU make一样,又比make简单多了。scons是python工具,需要先安装好python。 * Building/Testing: ================= JsonCpp uses Scons (http://www.scons.org) as a build system. Scons requires python to be installed (http://www.python.org). You download scons-local distribution from the following url: http://sourceforge.net/projects/scons/files/scons-local/1.2.0/ 文档中是这么写,不过scons已经到了2.1.0版了 下载scons-src-2.1.0,解压。不需要编译安装,可以直接使用源码,放在 jsoncpp的readme所在的目录下 具体到jsoncpp的编译,可以进入到jsoncpp目录,执行 python scons.py platform=mingw 生成jsoncpp-src-0.6.0-rc2libsmingwlibjson_mingw_libmt.a 库文件。 把include目录和.a文件放在编译环境的相应目录中 接下来可以在devcpp中开一个源文件 #include <iostream> #include <cstdlib> #include <string> #include <jsonjson.h> using namespace std; int main(int argc,char * argv[]) { string strValue = "{"key1":"value1","array":[{"key2":"value2"},{"key2":"value3"},{"key2":"value4"}]}"; Json::Value v; Json::Reader reader; if(reader.parse(strValue,v)) { string out = v["key1"].asString(); cout << out << endl; const Json::Value arrayObj = v["array"]; for(int i = 0; i < arrayObj.size(); i ++) { out = arrayObj[i]["key2"].asString(); cout << out ; if(i != arrayObj.size()-1) cout << endl; } } cout << endl; Json::Value root; Json::Value arrayObj; Json::Value item; for(int i = 0; i < 10 ; i ++) { item["key"] = i; arrayObj.append(item); } root["key1"] = "value1"; root["key2"] = "value2"; root["array"] = arrayObj; root.toStyledString(); string out = root.toStyledString(); cout << out <<endl; Json::FastWriter writer; string res = writer.write(root); cout << res << endl; cout << endl; system("pause"); return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |