2016-04-29 31 views
1

我试图编译这个程序:C++ rapidjson “ 'rapidjson ::文件' 没有名为成员 'GetParseErrorCode'”

`

#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; 
} 

`

但总是收到此错误: `

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())); 

` 我将如何解决日是问题吗?因为根据rapidjson文档,这是做到这一点的正确方法。或者是否有人知道更好的方式来解析JSON与C++?

回答

0

GetParseErrorCode应该是GetParseError - 这是文档中的错误。另外,在JSON中,[ [ Object ] ]不是正确的值。