我有以下代码将数据添加到 rapidjson::Document,声明如下:
rapidjson::Document rest;
rest.SetObject();
在一个循环中。
Value v(value.c_str());
stringstream ss;//create a stringstream
ss << "a" << colnum;
const char* colnumstr = ss.str().c_str();
cout << "json: colnumstr = \"" << colnumstr << "\", value = \"" << value << "\"" << endl;
rest.AddMember(colnumstr,v,rest.GetAllocator());
当循环结束时,我将 json 作为字符串添加到地图中,如下所示:
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
rest.Accept(writer);
string reststring = buffer.GetString();
cout << "Pushing " << reststring << " to map" << endl;
parseddata["rest"].push_back(reststring);
这是奇怪的一点:
json: colnumstr = "a1", value = "13745438"
json: colnumstr = "a2", value = "#N/A"
json: colnumstr = "a9", value = "Top 19"
Pushing {"a1":"9999\u0000438","99":"#N/A","31":"Top 19"} to map
某些价值观似乎正在发生变化。但我不知道如何或为什么。