当前位置:首页 > 编程笔记 > 正文
已解决

UDP端口接收到的字节流如何转为QJsonObject、QJsonArray的方法

来自网友在路上 11318131提问 提问时间:2023-11-21 15:51:03阅读次数: 131

最佳答案 问答题库1318位专家为你答疑解惑

//配置应答--检测点设置写文件if(p9==0x03){//需要注意:json对象中的[]应转成JsonArray,{}应转成JsonObject,p10是json字符串QJsonDocument jsonDocument = QJsonDocument::fromJson(p10);//从传入的json字符串中生成一个json文件QJsonObject convertedJsonObject = jsonDocument.object();//从json文件中转成json对象QJsonArray p_Object = convertedJsonObject["pointsArray"].toArray();//从json对象中取到jsonArrayfor(int i=1;i<=SUPPORTED_MAX_POINTS_PERCAMERA;i++){paramsPoint point;//根据接收的修改后的配置文件创建一个类并更新QJsonObject p_sub_Object = p_Object.at(i-1).toObject();point.setX(p_sub_Object["x"].toInt());//设置主检测点坐标xpoint.setY(p_sub_Object["y"].toInt());//设置主检测点坐标ypoint.setName(p_sub_Object["name"].toString());//设置检测点名称point.setValid(p_sub_Object["valid"].toInt());//设置主检测点是否有效point.setSubValid(p_sub_Object["subvalid"].toInt());//设置辅检测点是否有效// 获取subpoint对象paramsSubPoint params_sub_point;QJsonObject sub_point_Object = p_sub_Object["subpoint"].toObject();params_sub_point.setX(sub_point_Object["x"].toInt());params_sub_point.setY(sub_point_Object["y"].toInt());point.setSubpoint(params_sub_point);//设置辅检测点:subpoint// 获取Channel4U对象params4UDirection params_chnnel_4u;QJsonObject chnnel_4u_Object = p_sub_Object["channel4U"].toObject();params_chnnel_4u.setChannel(chnnel_4u_Object["channel"].toInt());params_chnnel_4u.setDirection(chnnel_4u_Object["direction"].toInt());point.setChannel4U(params_chnnel_4u);//设置4U通道:Channel4Upoint.setChannelNo(p_sub_Object["channelNo"].toInt());//设置通道号// 获取PointType对象paramsChannelType params_PointType;QJsonObject ChannelType_Object = p_sub_Object["pointtype"].toObject();params_PointType.setGoChannel(p_sub_Object["go"].toInt(),p_sub_Object["goEN"].toInt());params_PointType.setLeftChannel(p_sub_Object["left"].toInt(),p_sub_Object["leftEN"].toInt());params_PointType.setLeftChannel(p_sub_Object["right"].toInt(),p_sub_Object["rightEN"].toInt());point.setPointtype(params_PointType);//设置检测点类型:pointTypepoint.setRedLightX(p_sub_Object["redlightx"].toInt());//红灯坐标xpoint.setRedLightY(p_sub_Object["redlighty"].toInt());//红灯坐标ypoint.setSpecValid(p_sub_Object["specvalid"].toInt());//帧差轮廓专用点是否有效paramsSpecPoint params_spec_point;QJsonObject spec_point_Object = p_sub_Object["specpoint"].toObject();params_spec_point.setX(spec_point_Object["x"].toInt());params_spec_point.setX(spec_point_Object["y"].toInt());point.setSpecpoint(params_spec_point);//设置专用点坐标:spec_pointpoint.setQueueValid(p_sub_Object["queue"].toInt());//设置是否计算排队长度point.setCheckmethod(p_sub_Object["checkmethod"].toInt());//设置检车算法point.setGreenLightX(p_sub_Object["greenlightx"].toInt());//设置绿灯坐标xpoint.setGreenLightY(p_sub_Object["greenlighty"].toInt());//设置绿灯坐标ypoint.setGreenLessInterval(p_sub_Object["greenLessInterval"].toInt());//设置绿损间隔gCarDetectorParams.configParams.getCamera(camId)->setPoint(i,point);//依次更新各检测点的参数}gCarDetectorParams.saveparam();//最后更新配置文件}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"UDP端口接收到的字节流如何转为QJsonObject、QJsonArray的方法":http://eshow365.cn/6-41350-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!