I have a return string from my webservice as such:
std::string json_str = "{"Count":18,"Result":[{"Description":"DATABASE TASK MODE VALUE","Name":"TASK","Val":24,"addID":0,"CreatedAt":"2015-08-12T17:57:03.954Z","ModifiedAt":"2015-08-13T20:41:30.900Z","CreatedBy":"00000000-0000-0000-0000-000000000000","ModifiedBy":"00000000-0000-0000-0000-000000000000","Owner":"00000000-0000-0000-0000-000000000000","Id":"89fb5320-411b-11e5-a0dc-8babbc75a180","Meta":{"Permissions":{"CanRead":true,"CanUpdate":true,"CanDelete":true}}}, ...etc ]}"
this code works
document.Parse(json_str.c_str()).HasParseError())
assert(document.IsObject());
rapidjson::Value::MemberIterator localdata_0 = document.FindMember("89fb5320-411b-11e5-a0dc-8babbc75a180");
But then it fails on these lines
assert(localdata_0 != document.MemberEnd());
assert(localdata_0->value.IsDouble());
Is there an easy way to format my string to the correct json format as such?
const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
The solution is to cut up the string into rows and parse that instead. Put each string row into a vector.
std::vector <std::string> json_str_rows;
std::vector <float> json_float_ret;
// get values from rows
try
{
for (size_t i = 0; i < json_str_rows.size(); i++)
{
if (document.Parse((json_str_rows.at(i)).c_str()).HasParseError())
{
std::cerr << "system_rapidjson::read_json_str >> document.Parse >> ERROR at(" << i << ") = " << json_str_rows.at(i) << std::endl;
throw -3;
}
json_float_ret.push_back (document["Val"].GetDouble()); // get value from row
}
}
catch (const std::exception &e)
{
std::cerr << "system_rapidjson::read_json_str >> get values from rows >> ERROR = " << e.what() << std::endl;
throw -2;
}