你拥有的那个“字符串”是 JSON 格式的,PHP 有一些内置的函数可以使用它!
您可以使用json_decode将其转换为对象或数组
这是一个将其转换为 PHP 数组的示例:
<?php
$json = '[{"title":"Image One","description":"Image One\r\nDescription","image":{"attachment_id":"111"}},{"title":"Image Two","description":"Image Two Description","image":{"attachment_id":"222"}},{"title":"Image Three","description":"Image Three\r\nDescription","image":{"attachment_id":"333"}}]';
$data = json_decode($json, true);
print_r($data);
其输出为:
Array
(
[0] => Array
(
[title] => Image One
[description] => Image One
Description
[image] => Array
(
[attachment_id] => 111
)
)
[1] => Array
(
[title] => Image Two
[description] => Image Two Description
[image] => Array
(
[attachment_id] => 222
)
)
[2] => Array
(
[title] => Image Three
[description] => Image Three
Description
[image] => Array
(
[attachment_id] => 333
)
)
)