如何将JSON转换为php字符串[重复]

问题描述 投票:-1回答:2

这个问题在这里已有答案:

我有这样的JSON数据

["pdf","xlsx","docx"]

我想将JSON改为这样

pdf,xlsx,docx

现在我使用这个代码,但我认为这不是最好的方法

str_replace (array ('[', '"', ']'), '', $ jsondata)

请告诉我将JSON转换为预期的最佳方法

php laravel lumen
2个回答
1
投票

简单尝试json_decode()implode()

<?php
$json = '["pdf","xlsx","docx"]';
$string = implode(',',json_decode($json,1));
echo $string;
?>

输出:

pdf,xlsx,docx

但是:Kua zxsw指出


0
投票

使用内置https://3v4l.org/BEEsZ的php,然后使用json_decode

喜欢,

implode

$str = '["pdf","xlsx","docx"]'; print_r(implode(",",json_decode($str)));

© www.soinside.com 2019 - 2024. All rights reserved.