0

Вот как полностью выглядит ошибка

rapidjson::GenericValue<Encoding, Allocator>& rapidjson::GenericValue<Encoding, Allocator>::AddMember(rapidjson::GenericValue<Encoding, Allocator>&, rapidjson::GenericValue<Encoding, Allocator>&, Allocator&) [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>]: Assertion `IsObject()' failed.

Вот код:

rapidjson::Document Message::to_json() {
        rapidjson::Document document;
        rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
        rapidjson::Value jsonMessage(rapidjson::kObjectType);
        rapidjson::Value login;
        rapidjson::Value loginColor;
        rapidjson::Value imageSource;
        rapidjson::Value message;
        rapidjson::Value time;
        rapidjson::Value firstMessage;

        login.SetString(_login.c_str(), _login.size(),allocator);
        loginColor.SetString(_loginColor.c_str(), _loginColor.size(),allocator);
        imageSource.SetString(_imageSource.c_str(), _imageSource.size(),allocator);
        message.SetString(_message.c_str(), _message.size(),allocator);
        time.SetString(_time.c_str(), _time.size(),allocator);
        firstMessage.SetBool(_firstmessage);

        jsonMessage.AddMember("login", login ,allocator);
        jsonMessage.AddMember("loginColor", loginColor,allocator);
        jsonMessage.AddMember("imageSource", imageSource,allocator);
        jsonMessage.AddMember("message", message,allocator);
        jsonMessage.AddMember("time", time,allocator);
        jsonMessage.AddMember("firstMessage", firstMessage,allocator);
      
        document.AddMember("message", jsonMessage, document.GetAllocator()); // EXCEPTION HERE

        return document;
    }

1 ответ 1

1

По-умолчанию экземпляры rapidjson::Document создаются с категорией Null, чтобы сделать из документа объект следует вызвать document.SetObject();.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.