Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Wordpress post meta转换为PHP数组_Php_Mysql_Arrays_Wordpress - Fatal编程技术网

将Wordpress post meta转换为PHP数组

将Wordpress post meta转换为PHP数组,php,mysql,arrays,wordpress,Php,Mysql,Arrays,Wordpress,我有一个Wordpress发布到MySql的元数据,就像 [{"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":""}]

我有一个Wordpress发布到MySql的元数据,就像

[{"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 = '[{"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":""}]';
$data = json_decode( $json );
var_dump( $data );
然后你会得到:

array(1) {
  [0]=>
  object(stdClass)#1 (10) {
    ["field"]=>
    string(7) "Email:1"
    ["title"]=>
    string(5) "email"
    ["explanation_text"]=>
    string(0) ""
    ["explanation_text_location"]=>
    string(0) ""
    ["html_styling"]=>
    string(0) ""
    ["text_to_display"]=>
    string(0) ""
    ["show_title_field"]=>
    string(0) ""
    ["pdf_file"]=>
    string(0) ""
    ["pdf_file_button_styling"]=>
    string(0) ""
    ["pdf_file_button_text"]=>
    string(0) ""
  }
}

使用json_解码而不是json_encode@user3384985数据不是序列化的类型,它
json\u encode
您需要使用
json\u decode