为什么我在编译RapidJSON时收到错误
Why I receive error while compiling RapidJSON
使用RapidJSON解析JSON文件时,我会收到这些错误。
这是JSON文件的一部分:
{
"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"];
我得到这个错误。我不知道上面怎么说他们没有会员。
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();
header
是rapidjson::Value
类型的对象,不具有protocolVersion
、messageID
和stationID
成员。您应该提供自定义对象类型来存储header
中的值。其他变量(cam
和referencePosition
(也是如此。例如:
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;
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Rapidjson 解析错误:字符串 (207) 中的编码无效
- 为什么在复制rapidjson::Document时出现链接器错误而不是编译错误
- Json解析使用rapidJson在c++中给出错误
- CURLOPTS内容的c++rapidjson解析错误
- 如果第一个json有错误,Rapidjson解析另一个json