这个问题在这里已有答案:
我有这样的JSON数据
["pdf","xlsx","docx"]
我想将JSON改为这样
pdf,xlsx,docx
现在我使用这个代码,但我认为这不是最好的方法
str_replace (array ('[', '"', ']'), '', $ jsondata)
请告诉我将JSON转换为预期的最佳方法
简单尝试json_decode()
和implode()
<?php
$json = '["pdf","xlsx","docx"]';
$string = implode(',',json_decode($json,1));
echo $string;
?>
输出:
pdf,xlsx,docx
但是:Kua zxsw指出
使用内置https://3v4l.org/BEEsZ的php,然后使用json_decode
喜欢,
implode
$str = '["pdf","xlsx","docx"]';
print_r(implode(",",json_decode($str)));