加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 删除json中的括号?

发布时间:2020-12-13 18:28:12 所属栏目:PHP教程 来源:网络整理
导读:如何摆脱下面的括号进行json处理? [{"success":true,"filename":"bialding_and_rebialding_plymouth02.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth03.jpg"},"filename":"bialding_and_rebialding_plymouth04.jpg"}] 上面的结果由
如何摆脱下面的括号进行json处理?
[{"success":true,"filename":"bialding_and_rebialding_plymouth02.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth03.jpg"},"filename":"bialding_and_rebialding_plymouth04.jpg"}]

上面的结果由下面的类处理成一个数组,

function handle_upload($upload_directory)
    {
        # Loop the code according to the number of files.
        for($i = 1; $i <= $this->total; $i++)
        {
            ...

            if ($this->file->save($upload_directory.$name_filtered.'.'.$file_extension,$i-1))
            {
                $message[] = array('success'=>true,'filename'=>$name_filtered.'.'.$file_extension);
            }
            else 
            {
                $message[] = array('error'=> 'Could not save uploaded file.' . 'The upload was cancelled,or server error encountered');
            }
        }

        return $message;
    }

然后我使用json_encode将数组转换为json格式,

$uploader = new uploader();
$result = $uploader->handle_upload('uploads/');

echo htmlspecialchars(json_encode($result),ENT_NOQUOTES);

但我只在没有括号的结果中需要这个,

{"success":true,"filename":"bialding_and_rebialding_plymouth04.jpg"}
str_replace(array(‘[‘,’]’),”,htmlspecialchars(json_encode($result),ENT_NOQUOTES)); ?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读