【发布时间】:2019-07-22 00:11:16
【问题描述】:
我有这样的 JSON 数据
["pdf","xlsx","docx"]
我想把 JSON 改成这样
pdf,xlsx,docx
现在我使用此代码,但我认为这不是最好的方法
str_replace (array ('[', '"', ']'), '', $ jsondata)
请教我将 JSON 转换为预期的最佳方法
【问题讨论】:
我有这样的 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
【讨论】:
使用php内置json_decode然后implode
喜欢,
$str = '["pdf","xlsx","docx"]';
print_r(implode(",",json_decode($str)));
【讨论】: