【发布时间】:2016-02-16 11:12:08
【问题描述】:
我有一个类似 MySql 的 Wordpress 帖子元数据
[{"field":"Email:1","title":"email","explanation_text":"","explanation_text_location":"","html_styling":"","text_to_display":"","show_title_field":"","pdf_file":"","pdf_file_button_styling":"","pdf_file_button_text":""}]
我需要将其转换为 PHP 数组。我使用以下代码将其作为数组。
$wpaf_field_title = maybe_unserialize(get_post_meta(52, '__wpaf_field_title', true));
print_r(json_encode($wpaf_field_title));
但它返回我
"[{\"field\":\"Email:1\",\"title\":\"email\",\"explanation_text\":\"\",\"explanation_text_location\":\"\",\"html_styling\":\"\",\"text_to_display\":\"\",\"show_title_field\":\"\",\"pdf_file\":\"\",\"pdf_file_button_styling\":\"\",\"pdf_file_button_text\":\"\"}]"
【问题讨论】:
-
使用 json_decode 代替 json_encode
-
@user3384985数据不是序列化的类型
json_encode你需要使用json_decode。
标签: php mysql arrays wordpress