字符串轉json格式

1. 添加json.h、json-forwards.h、jsoncpp.cpp文件(網上有);

2. 

	Json::CharReaderBuilder b;
	Json::CharReader* reader(b.newCharReader());
	Json::Value json_object;
	JSONCPP_STRING errs;
	const char* statusBuf = R"({"prod_line": "OS - 2 - 64 - G", "prod_pn": "840 - 102146 - 05", "prod_sn": "992205000761", "image_rev": "ousteros - image - prod - aries - v2.2.1 + 20220215193703.patch - v2.2.1", "build_rev": "v2.2.1", "build_date": "2022 - 02 - 15T19:39 : 39Z", "status": "RUNNING", "initialization_id": 7109745, "base_pn": "", "base_sn": "", "proto_rev": ""})";
	bool okB = reader->parse(statusBuf, statusBuf + std::strlen(statusBuf), &json_object, &errs);
	if (okB && errs.size()==0)
	{
		varC = json_object["status"].asCString();
	}
	else
	{
		std::cout << "json get fail.." << std::endl;
	}
	delete reader;

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章