I'm attempting to loop through a list of objects within a JSON to find the object with a matching KVP (in C++ using RapidJSON). I've managed to retrieve the value using a hardcoded pointer but cannot get the function GetValueByPointer(document, "PointerString")
to accept the dynamic string I am building.
The JSON looks like this:
{ "_id" : { "$oid" : "5d0985973f1c0000ee000000" },
"Location" : [ { "lat" : "39.4005", "lon" : "-106.106"} ],
"Weather" : [ { "timestamp" : "2019-06-05T00:00:00", ...}, { "timestamp" : "2019-06-05T01:00:00", ...}}
This works:
Document document;
document.Parse(json);
Value* a = GetValueByPointer(document, "/Weather/1/timestamp");
std::cout << a->GetString() << std::endl;
This doesn't work:
Value* a = GetValueByPointer(document, "/Weather/1/timestamp");
int i = 1;
std::string base = "/Weather/";
std::string tail = "/timestamp";
std::string PointerString;
std::string TSString = "";
while(TSString != "2019-06-05T09:00:00") {
PointerString=base;
PointerString.append(std::to_string(i));
PointerString.append(tail);
PointerString = "\"" + PointerString + "\"";
Value* timestamp = GetValueByPointer(document, PointerString);
TSString = timestamp->GetString();
std::cout << TSString << std::endl;
i++;
}
The error I get no matter what I try and convert my PointerString to is:
/usr/local/include/rapidjson/pointer.h:1156:30: note: template argument deduction/substitution failed:
MGOIO.cc:145:62: note: mismatched types ‘const CharType [N]’ and ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’
Value* timestamp = GetValueByPointer(document, PointerString);
^
When I output PointerString
to the screen it looks good to me:
"/Weather/1/timestamp"
Any help is most appreciated!