Rapidjson: RapidJson kArrayType with std::string

Created on 22 Sep 2016  Â·  1Comment  Â·  Source: Tencent/rapidjson

I have following code but its cannot compiled. I cannot think about a reason, please help.

rapidjson::Document jsonDoc;
jsonDoc.SetObject();
rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator();

rapidjson::Value messageArr(rapidjson::kArrayType);

std::string test = std::string("TEST");
messageArr.PushBack(test.c_str(), allocator);

Giving me following error;
error: no matching function for call to ‘rapidjson::GenericValue >::PushBack(const char*, rapidjson::GenericDocument >::AllocatorType&)’ messageArr.PushBack(test.c_str(), allocator);

Most helpful comment

You need an allocator to create/copy the string as well:

rapidjson::Value testStr(test.c_str(), allocator);
messageArr.PushBack(testStr, allocator);

>All comments

You need an allocator to create/copy the string as well:

rapidjson::Value testStr(test.c_str(), allocator);
messageArr.PushBack(testStr, allocator);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Andy1978 picture Andy1978  Â·  3Comments

OlafvdSpek picture OlafvdSpek  Â·  6Comments

frankw2 picture frankw2  Â·  3Comments

leeyiw picture leeyiw  Â·  4Comments

dan-ryan picture dan-ryan  Â·  6Comments