对json格式的数据进行解析

 public String updateAlbumAndVideoRelation(String param) throws TException {
        logger.info("[ProgramRpcManager][updateAlbumAndVideoRelation][step:start][param={}]",param);
        String result = "";
        try{
            JSONArray relationJsonArr=JSONArray.fromObject(param);
            if(relationJsonArr==null)//传递空数据
            {
                result=Constants.getResponseStr(Constants.CODE_FAIL,"传递的参数错误,参数为空");
            }else{
                for(int i=0;i<relationJsonArr.size();i++)
                {
                    JSONObject relationObj=relationJsonArr.getJSONObject(i);
                    Long qipuId=relationObj.getLong("qipuId");//不允许为空

                    Long albumId=null;
                    Integer videoOrder=null;
                    boolean isBound=relationObj.getBoolean("isBound");
                    if(isBound)//当需要进行绑定时候获取专辑ID以及videoOrder
                    {
                        String videoOrderStr=relationObj.getString("videoOrder");
                        videoOrder  = StringUtil.toInteger(videoOrderStr, 1);
                        albumId=relationObj.getLong("albumId");//
                    }
                    Video video=videoService.getByQipuId(qipuId);//获取对应的视频
                    if(video==null||video.getId()==null){
                        result=Constants.getResponseStr(Constants.CODE_ERROR_NOT_EXIST_PROGRAM,"不存在该视频");
                    }else {
                        //更新视频与专辑的关系
                        if (videoService.updateAlbumAndVideoRelation(video, albumId, videoOrder)) {
                            result = Constants.getResponseStr(Constants.CODE_SUC);
                        } else {
                            result = Constants.getResponseStr(Constants.CODE_FAIL);
                        }
                    }
                }
            }

        }catch(Exception e){
            //接受的数据不是JSONArray类型则抛出异常
            result = Constants.getResponseStr(Constants.CODE_FAIL,"传递的数据不完整:"+ e.getMessage());
            logger.error("[ProgramRpcManager][updateAlbumAndVideoRelation][step:exception][param={}]",param,e);
        }
        return result;
    }
对json格式的数据进行解析,如果出现值为空,例如标红部分,则会出现解析异常,此时线程会继续运行,并不会终止。
{'isBound':false,'qipuId':90009900,'albumId':,'videoOrder':null},
* {'isBound':true,'qipuId':90010100,'albumId':50000052,'videoOrder':1}]" 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值