I want to extract a specific array from a json file:
{
"status": "OK",
"type": "startVehicle",
"info": {
"idTransit": 36612,
"timestampUTCTransit": {
"epochUTCTransitMS": 1606935562810,
"dateUTCTransit": "2020/12/2",
"hourUTCTransit": "18:59:22.810"
},
"timestampUTCReported": {
"epochUTCReportedMS": 1606935562810,
"dateUTCReported": "2020/12/2",
"hourUTCReported": "18:59:22.810"
},
"road": 0,
"lane": 0,
"xCoordinates": [
143.6,
-456.335
]
}
}
I want extract the values of xCoordinates. This is what I tried:
#include <rapidjson/document.h>
void Vdac::addStart(std::string json_str)
{
Document rjsondoc;
rjsondoc.Parse(json_str.c_str());
if(rjsondoc.HasParseError())
slog.getLogger()->debug("Invalid json");
else
{
auto coordinates = rjsondoc["info"]["xCoordinates"].GetArray();
for(SizeType i=0;i<coordinates.Size();i++)
slog.getLogger()->debug("The start coordinates are: {0:d}",coordinates[i].GetInt());
return;
}
}
But I have an error when the program accesses the value. The error is:
../include/rapidjson/document.h:1737: int rapidjson::GenericValue<Encoding, Allocator>::GetInt() const [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>]: Assertion `data_.f.flags & kIntFlag' failed.
How can I extract the value?