Bootstrap

C++实现json字符串与map的转换

开源资源库

jsoncpp-src-0.5.0.tar.gz:
https://sourceforge.net/projects/jsoncpp/

jsoncpp-master.zip
https://github.com/open-source-parsers/jsoncpp

下面以jsoncpp050版本为例

1:map转化为jsonstr

#include "json.h"
string map2jsonstr(const map<string,string>& map_info) { Json::Value jObject; for (map<string, string>::const_iterator iter = map_info.begin( ); iter != map_info.end( ); ++iter) { jObject[iter->first] = iter->second; } return jObject.toStyledString(); }

2:jsonstr转化为map

string itoa_self(int i)
{
	stringstream ss;
	ss << i;
	return ss.str();
}

map<string,string> jsonstr2map(const string& json)
{
	Json::Reader reader;
	Json::V
;