我希望我的 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);
关于PHP json_encode { } 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26132873/