I am trying to compile this program:
`
#include "rapidjson/document.h"
#include "rapidjson/error/en.h"
#include <stdio.h>
#include <iostream>
int main() {
const char* json =
"{"
"\"hello\": \"world\","
"\"t\": \"world\""
"}";
const char* msgJson =
"{"
"\"t\": \"MESSAGE_CREATE\","
"\"s\": 59,"
"\"op\": 0,"
"\"d\":{"
"\"tts\": false,"
"\"timestamp\": \"2016-04-29T02:40:47.490000+00:00\","
"\"nonce\": \"175436196699176960\","
"\"mentions\": [ [Object] ],"
"\"mention_everyone\": false,"
"\"id\": \"175436191456428032\","
"\"embeds\": [],"
"\"edited_timestamp\": null,"
"\"content\": \"<@174463430873317376> count stuff\","
"\"channel_id\": \"81402706320699392\","
"\"author\": {"
"\"username\": \"#C2185B #AD1457 #880E4F\","
"\"id\": \"125422419736395777\","
"\"discriminator\": \"0672\","
"\"avatar\": \"57ca1bf97372796648a2aac4b20614af\""
"},"
"\"attachments\": []"
"}"
"}";
rapidjson::Document document;
document.Parse(json);
assert(document.IsObject());
assert(document.HasMember("hello"));
assert(document["hello"].IsString());
printf("hello = %s\n", document["hello"].GetString());
assert(document.HasMember("t"));
assert(document["t"].IsString());
printf("t = %s\n", document["t"].GetString());
rapidjson::Document message;
rapidjson::ParseResult result = message.Parse(msgJson);
//std::cout << rapidjson::ParseErrorCode << std::endl;
printf("%u - %s\n", (unsigned)message.GetErrorOffset(), rapidjson::GetParseError_En(message.GetParseErrorCode()));
assert(message.IsObject());
assert(message.HasMember("t"));
printf("%s\n", message["t"].GetString());
return 0;
}
`
but keep getting this error: `
json_example.cpp: In function ‘int main()’:
json_example.cpp:53:97: error: ‘rapidjson::Document’ has no member named ‘GetParseErrorCode’
printf("%u - %s\n", (unsigned)message.GetErrorOffset(), rapidjson::GetParseError_En(message.GetParseErrorCode()));
` How would I solve this problem? Because according to the rapidjson docs this is the correct way to do it. Or does anyone know of a better way to parse JSON with C++?
GetParseErrorCode
should be GetParseError
- this was a mistake in the docs. Also, in the JSON, [ [ Object ] ]
isn't a correct value.