我有来自get_post_meta的生成数据,我需要将其转换为JSON。生成的数组如下:
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[rate] => 5
[review] => Array
(
[content] => Test Review
[custom_field_1] => Azman Ishak
[custom_field_2] => Selagnor
[date] => 2017-06-06 , 15:06
[title] =>
[status] => publish
[weight] => 5
)
[user] => Array
(
[name] => ebeneadmin
[email] => azman@considerdigital.com
[id] => 1
[ip] => 115.135.10.5
)
)
)
)
[1] => Array
(
[0] => Array
(
[0] => Array
(
[rate] => 4
[review] => Array
(
[content] => Test review 2
[custom_field_1] => Azman
[custom_field_2] => Beranang
[date] => 2017-06-06 , 16:01
[title] =>
[status] => publish
[weight] => 5
)
[user] => Array
(
[name] => Azman Ishak
[email] => azmunk@gmail.com
[id] =>
[ip] => 115.135.10.5
)
)
)
)
[2] => Array
(
[0] => Array
(
)
)
)
我需要从上面的数组获得的值是:
此数据需要转换为JSON。
答案 0 :(得分:1)
试试这个:
将您的get_post_meta结果转换为json_encode();
它会使你的结果
<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>
输出:
{"a":1,"b":2,"c":3,"d":4,"e":5}