如何将JSON转换为php字符串

时间:2019-02-28 06:21:46

标签: php laravel lumen

我有这样的JSON数据

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

我想将JSON更改为这样

pdf,xlsx,docx

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

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

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

2 个答案:

答案 0 :(得分:1)

简单尝试使用json_decode()implode()

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

输出:

pdf,xlsx,docx

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

答案 1 :(得分:0)

使用json_decodeimplode内置的php

就像

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

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

Demo