html转义json,json转数组 反转

$institution="";
         $str='{"member.realname":"小1","institution":"178","createtime":"2018-09-13 00:00:00 - 2018-09-19 23:59:59"}';
        
        $arr = json_decode(htmlspecialchars_decode($str),true);//字符转义,再json转数组
        
        foreach($arr as $name=>$value)
        {
            $where_arr[$name]=$value;
            if($name == 'institution')
            {
                $where_arr['institution']=$value;
            }
            else if($name == 'createtime')
            {
                $where_arr['createtime']=array('between',array(substr($arr['createtime'],0,19),substr($arr['createtime'],-19)));
            }
        }
    //去机构id
        if (array_key_exists("institution",$arr))
        {
            $institution=$arr['institution'];
            $arr= $this->array_remove($arr,'institution'); 
        }
        //数组转json,保留中文
        $jsonObj_1 = json_encode($arr,JSON_UNESCAPED_UNICODE);
        $result_str=htmlspecialchars($jsonObj_1);//好像不需要  转会html
    
        dump($result_str);

猜你喜欢

转载自blog.csdn.net/u013685199/article/details/82775007