在Rapidjson中使用AddMember时获得无效的价值
Getting Null value on using AddMember in rapidjson
我正在尝试使用RapidJson和VC 创建JSON字符串。以下是我的代码:
WDocument saveDoc;
WValue settingDoc(kObjectType);
settingDoc.AddMember("BOOK_ID", "456723", saveDoc.GetAllocator());
settingDoc.AddMember("BOOK_FOUND", true, saveDoc.GetAllocator());
WValue wImplVal;
wImplVal.SetString(BookName, saveDoc.GetAllocator()); //TCHAR BookName[MAX_PATH]
settingDoc.AddMember("BOOK_NAME", wImplVal, saveDoc.GetAllocator()); //gets correct book name
settingDoc.AddMember("BOOK_NICK_NAME",wImplVal,saveDoc.GetAllocator());//gets null value in wImplVal
saveDoc.SetObject();
saveDoc.AddMember("BOOK_INFO", settingDoc, saveDoc.GetAllocator());
我第二次获得无效的值,即使我没有修改它,也可以使用Wimplval。我们是否有一些特殊规则可以在Rapidjson中的两个键中添加一个值。预先感谢。
如果您仔细阅读此内容,尤其是"移动语义"部分,您可以确定Rapidjson Value Ass使用的,嗯,移动语义,因此当您将其传递给Null
时,它会移动现有值并用CC_3。
当Rapidjson支持C 03时,它使用分配操作员采用移动语义,以及所有其他修改功能(如AddMember)(),buthback()。
因此,您必须再次设置价值才能获得想要的东西。
WDocument saveDoc;
WValue settingDoc(kObjectType);
settingDoc.AddMember("BOOK_ID", "456723", saveDoc.GetAllocator());
settingDoc.AddMember("BOOK_FOUND", true, saveDoc.GetAllocator());
WValue wImplVal;
wImplVal.SetString(BookName, saveDoc.GetAllocator()); //TCHAR BookName[MAX_PATH]
settingDoc.AddMember("BOOK_NAME", wImplVal, saveDoc.GetAllocator()); //gets correct book name
wImplVal.SetString(BookName, saveDoc.GetAllocator());
settingDoc.AddMember("BOOK_NICK_NAME",wImplVal,saveDoc.GetAllocator());//gets null value in wImplVal
saveDoc.SetObject();
saveDoc.AddMember("BOOK_INFO", settingDoc, saveDoc.GetAllocator());
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- FFMPEG配置文件级别id大小无效
- 错误:从"int"到枚举c++的转换无效
- 如何修复此错误:className::className的无效使用
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- C++-模板嵌套类的引用初始化无效
- 错误:无效的预处理指令 #i 的意思是 #if?
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- 从 'int' 到 'int*' CPP 的转换无效
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- Rapidjson 解析错误:字符串 (207) 中的编码无效
- 在Rapidjson中使用AddMember时获得无效的价值