5
如何摆脱下面的json处理的括号?删除json中的括号?
[{"success":true,"filename":"bialding_and_rebialding_plymouth02.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth03.jpg"},{"success":true,"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_plymouth02.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth03.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth04.jpg"}
没有括号,你的json字符串将是无效的。一个JSON字符串可以只包含一个值。使用括号,它是一个数组或对象。没有括号,它是一系列单独的逗号分隔对象 - 无效。 –
不再有效的json。 – hop
为什么你不想'']'?你打算怎么处理结果字符串? –