如何将 JSON 转换为 php 字符串

How to convert JSON into php string

我有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

演示: https://3v4l.org/BEEsZ

使用 json_decode 内置的 php 然后 implode

喜欢,

$str = '["pdf","xlsx","docx"]';

print_r(implode(",",json_decode($str)));

Demo