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

//配置应答--检测点设置写文件
                    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对象中取到jsonArray
                        
                        for(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());//设置主检测点坐标x
                            point.setY(p_sub_Object["y"].toInt());//设置主检测点坐标y
                            point.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通道:Channel4U
                            
                            point.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);//设置检测点类型:pointType
                            
                            point.setRedLightX(p_sub_Object["redlightx"].toInt());//红灯坐标x
                            point.setRedLightY(p_sub_Object["redlighty"].toInt());//红灯坐标y
                            point.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_point
                            
                            point.setQueueValid(p_sub_Object["queue"].toInt());//设置是否计算排队长度
                            point.setCheckmethod(p_sub_Object["checkmethod"].toInt());//设置检车算法
                            point.setGreenLightX(p_sub_Object["greenlightx"].toInt());//设置绿灯坐标x
                            point.setGreenLightY(p_sub_Object["greenlighty"].toInt());//设置绿灯坐标y
                            point.setGreenLessInterval(p_sub_Object["greenLessInterval"].toInt());//设置绿损间隔
                            gCarDetectorParams.configParams.getCamera(camId)->setPoint(i,point);//依次更新各检测点的参数
                        }
                        gCarDetectorParams.saveparam();//最后更新配置文件
                    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值