C++中Json和Json对象互转

#include 
#include 
using namespace std;
int main() {

	string jsonTxt = "{\"name\":\"xiaoming\",\"age\":14,\"height\":179.5}";
	Json::Reader reader;
	Json::Value root;
	if (reader.parse(jsonTxt, root)) {
		cout << root["name"].asString() << endl;;
		cout << root["age"].asInt() << endl;;
		cout << root["height"].asDouble() << endl;;
	}
	//将Json对象转字符串
	Json::FastWriter fastWriter;
	std::string jsonStringFast = fastWriter.write(root);
	return 0;
}

你可能感兴趣的:(C++,c++,json,算法)