java - JSONArray问题。。。.
伊谢尔伦
伊谢尔伦 2017-04-17 17:25:49
0
1
501
public Map<String, Object> delete(JSONObject head, JSONObject body)
            throws Exception {
        Map<String, Object> attributes=new HashMap<String, Object>();
        JSONArray couponJson=body.optJSONArray("couponId");
         
            String token=head.optString("token");
        Object object=UserCacheManage.getAppUser(token);
        
        //if(object!=null){
        //UserCache user=(UserCache)object;
        String userId="4028668150c6aedb0150c6ddde750005";
        HhUserEntity hhUserEntity=super.getEntity(HhUserEntity.class, userId);
        if(hhUserEntity!=null){
            String ids="";
            Object [] couponIds=(Object[])couponJson.toArray();
            if(couponIds!=null&&couponIds.length>0){
                for(int i=0;i<couponIds.length;i++){
                    if(i==0){
                        ids=ids+"'"+couponIds[i]+"'";
                    }else{
                        ids=ids+",'"+couponIds[i]+"'";
                    }
                }    
            }
            
            String hql="from CouponPublishEntity e CouponPoolEntity d where d.owner='"+userId+"' and e.pubid in ("+ids+") ";
            List<HhCouponsEntity> list = super.findByQueryString(hql);
            if(list!=null&&list.size()>0){
                super.deleteAllEntitie(list);
            }

我要取到couponId然后批量删除实体,但是body.optJSONArray("couponId")得到的是object类型不是jsonarry类型,这怎么办- -

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
PHPzhong

Can’t I force transfer directly?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!