如何摆脱下面的括号进行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)); ?
原文链接:https://www.f2er.com/php/135937.html