我试图将一个 std::string 转换为以下格式的rapidJson 对象
{
"data":{
"value": "AB1234"
}
}
Run Code Online (Sandbox Code Playgroud)
我努力了
rapidjson::Document aJsonDocument;
aJsonDocument.SetObject();
rapidjson::Document::AllocatorType &aAllocator = aJsonDocument.GetAllocator();
rapidjson::Value aPsmJson(rapidjson::kStringType);
std::string aStr = "ABCDEF";
aPsmJson.SetString(aStr.c_str(), aAllocator);
aJsonDocument.AddMember("value", aPsmJson, aAllocator);
//jsonToString is a function to convert json document to string
std::string aInputJsonString = jsonToString(aJsonDocument);
std::cout << "Output: " << aInputJsonString ;
Run Code Online (Sandbox Code Playgroud)
这给出了输出 {"value":"ABCDEF"}
在将键,值对插入映射时,如果键为""并且对应该值存在,则行为是什么.例如
std::map<std::string, std::string> map1;
std::string key = "";
std::string value = "xyz";
map1.insert(std::pair<std::string, std::string>(key, value));
Run Code Online (Sandbox Code Playgroud)
处理这种情况的最佳方法是什么?