首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++ rapidjson“‘rapidjson::Document’没有名为‘GetParseErrorCode’的成员”

C++ rapidjson“‘rapidjson::Document’没有名为‘GetParseErrorCode’的成员”
EN

Stack Overflow用户
提问于 2016-04-29 09:54:13
回答 1查看 3.2K关注 0票数 1

我正在编写这个程序:

`

代码语言:javascript
复制
#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;
}

`

但是继续得到这个错误:

代码语言:javascript
复制
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的文档,这是正确的方法。或者,有人知道用C++解析JSON的更好方法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-29 10:19:35

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36935175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档