本文介绍了为什么我在编译 RapidJSON 时收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

使用 RapidJSON 解析 JSON 文件时出现这些错误.

Using RapidJSON for parsing a JSON file, I get these errors.

这是 JSON 文件的一部分:

This is part of the JSON file:

{
   "header":{
      "protocolVersion":2,
      "messageID":2,
      "stationID":224
   },
   "cam":{
      "generationDeltaTime":37909,
      "camParameters":{
         "basicContainer":{
            "stationType":5,

这是代码

 doc.Parse(pr);


    const auto& header = doc["header"];

    header.protocolVersion = doc["header"]["protocolVersion"].GetInt();
    header.messageID = doc["header"]["messageID"].GetInt();
    header.stationID = doc["header"]["stationID"].GetInt();


    const auto& cam = doc["cam"];


    cam.camParameters.basicContainer.stationType = doc["cam"]["camParameters"]["basicContainer"]["stationType"].GetInt();

    const auto& referencePosition = doc["cam"]["camParameters"]["basicContainer"]["referencePosition"];

我收到此错误.我不知道它说他们没有成员.

I get this error. I don't know what it says they have no member.

 In member function ‘void MqttApplication::sendm(const std::__cxx11::basic_string<char>&)’:
.cpp:389:12: error: ‘const class rapidjson::GenericValue<rapidjson::UTF8<> >’ has no member named ‘protocolVersion’
  389 |     header.protocolVersion = doc["header"]["protocolVersion"].GetInt();
      |            ^~~~~~~~~~~~~~~
mqtt_application.cpp:390:12: error: ‘const class rapidjson::GenericValue<rapidjson::UTF8<> >’ has no member named ‘messageID’
  390 |     header.messageID = doc["header"]["messageID"].GetInt();
      |            ^~~~~~~~~
mqtt_application.cpp:391:12: error: ‘const class rapidjson::GenericValue<rapidjson::UTF8<> >’ has no member named ‘stationID’
  391 |     header.stationID = doc["header"]["stationID"].GetInt();
      |            ^~~~~~~~~
mqtt_application.cpp:402:9: error: ‘const class rapidjson::GenericValue<rapidjson::UTF8<> >’ has no member named ‘generationDeltaTime’
  402 |     cam.generationDeltaTime = doc["cam"]["generationDeltaTime"].GetInt();
      |         ^~~~~~~~~~~~~~~~~~~
mqtt_application.cpp:405:9: error: ‘const class rapidjson::GenericValue<rapidjson::UTF8<> >’ has no member named ‘camParameters’
  405 |     cam.camParameters.basicContainer.stationType = doc["cam"]["camParameters"]["basicContainer"]["stationType"].GetInt();

推荐答案

headerrapidjson::Value 类型的对象,没有 protocolVersionmessageIDstationID 成员.您应该提供自定义对象类型来存储 header 中的值.其他变量(camreferencePosition)也是如此.例如:

header is object of rapidjson::Value type and doesn't have protocolVersion, messageID and stationID members. You should provide your custom object type to store values from header. The same goes for other variables (cam and referencePosition). For example:

struct MessageHeader
{
    int protocolVersion;
    int messageID;
    int stationID;
};

//...

const auto& header = doc["header"];

MessageHeader messageHeader;
messageHeader.protocolVersion = header["protocolVersion"].GetInt();
messageHeader.messageID = header["messageID"].GetInt();
messageHeader.stationID = header["stationID"].GetInt();

std::cout << "message header protocol version: " << messageHeader.protocolVersion << std::endl;

这篇关于为什么我在编译 RapidJSON 时收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 15:59