为什么 rapidjson 给我带来 std::string 的问题?

Why is rapidjson giving me problems with std::string?

我正在尝试将 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 快速 json 编辑我的 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.

有什么想法吗?

如果你有一个字符串:

std::string s = "myString"; 

你可以在RapidJson中使用数据和大小来设置它:

document["myValue"].SetString(s.data(), s.size(), document.GetAllocator());