【发布时间】:2019-04-09 05:56:50
【问题描述】:
我正在尝试将 std::string 与 RapidJson 一起使用
using namespace std;
using namespace rapidjson;
const char* json = "{\n"
" \"id\": null\n"
" \"code\": null\n"
"}";
Document d;
string a = "myString";
d["myValue"].SetString(a); //error: no matching member function for call to 'SetString' in the compiler
我只是希望能够使用 std::string 使用 rapidjson 编辑我的 json,但它不起作用。顺便说一句,c++ 新手,如果这是一个愚蠢的问题,请见谅。
编辑:我尝试了 Jorge Perez 的解决方案,但仍然收到此错误:
/include/rapidjson/document.h:1139: rapidjson::GenericValue<Encoding, Allocator>& rapidjson::GenericValue<Encoding, Allocator>::operator[](const rapidjson::GenericValue<Encoding, SourceAllocator>&) [with SourceAllocator = rapidjson::MemoryPoolAllocator<>; Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>]: Assertion `false' failed.
有什么想法吗?
【问题讨论】:
-
我确实有一个可用的 json,我可以使用 Document 拥有的其他 Set 方法。
-
不以什么方式工作?不编译?运行时崩溃?还有什么?请提供minimal reproducible example
-
它在编译之前给了我错误,我只是用更多的代码编辑了这个问题。
-
就个人而言,我会改用 nlohmann json 库。方式更简单,更易于使用。