简体   繁体   中英

PHP json_encode { } characters

I want my json_encode to have a serialized string of:

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

How do I do it?

I tried

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

produces:

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

Note the extra quotes

You nest it in another array:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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