繁体   English   中英

PHP json_encode {}个字符

[英]PHP json_encode { } characters

我希望json_encode的序列化字符串为:

 ['Element', 'Density', { role: 'style' }]

我该怎么做?

我试过了

   $data = array('Element', 'Density', "{ role: 'style' }");
   echo json_encode($data);

生产:

["Element","Density","{ role: 'style' }"]

注意多余的引号

您将其嵌套在另一个数组中:

$data = array('Element', 'Density', array('role' => 'style'));
                                  // ^ another nesting here
echo json_encode($data);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM