我在本地有一个wordpress网站,我正在尝试使用AngularJS
构建它的混合应用程序。
在wordpress中,我创建了一个插件来获取数据。我得到array
形式的元数据
Array
(
[REAL_HOMES_gallery_slider_type] => Array
(
[0] => thumb-on-right
)
[REAL_HOMES_property_images] => Array
(
[0] => 94
)
[REAL_HOMES_property_price] => Array
(
[0] => 3850
)
[REAL_HOMES_property_size] => Array
(
[0] => 2800
)
[REAL_HOMES_property_bedrooms] => Array
(
[0] => 2
)
[REAL_HOMES_property_bathrooms] => Array
(
[0] => 1
)
[REAL_HOMES_property_garage] => Array
(
[0] => 1
)
[REAL_HOMES_property_address] => Array
(
[0] => Athwa Gate, Surat, Gujarat 395008, India
)
[REAL_HOMES_property_location] => Array
(
[0] => 21.1852392,72.80947859999992
)
[REAL_HOMES_tour_video_url] => Array
(
[0] => http://vimeo.com/70301553
)
[REAL_HOMES_featured] => Array
(
[0] => 1
)
[REAL_HOMES_add_in_slider] => Array
(
[0] => no
)
[REAL_HOMES_agents] => Array
(
[0] => 110
)
[_dp_original] => Array
(
[0] => 75
)
[REAL_HOMES_property_price_postfix] => Array
(
[0] => Per Month
)
[_wp_old_slug] => Array
(
[0] => 15421-southwest-39th-terrace-fl
)
[REAL_HOMES_tour_video_image] => Array
(
[0] => 94
)
[REAL_HOMES_property_id] => Array
(
[0] => Aagam003
)
[REAL_HOMES_property_size_postfix] => Array
(
[0] => Sq Ft
)
[slide_template] => Array
(
[0] => default
)
[REAL_HOMES_agent_display_option] => Array
(
[0] => agent_info
)
[_edit_lock] => Array
(
[0] => 1436890564:1
)
[_edit_last] => Array
(
[0] => 1
)
[_thumbnail_id] => Array
(
[0] => 894
)
[REAL_HOMES_slider_image] => Array
(
[0] => 841
)
)
所以我把它转换成一个简单的array
,得到了下面的array
。
Array
(
[REAL_HOMES_gallery_slider_type] => thumb-on-right
[REAL_HOMES_property_images] => 94
[REAL_HOMES_property_price] => 3850
[REAL_HOMES_property_size] => 2800
[REAL_HOMES_property_bedrooms] => 2
[REAL_HOMES_property_bathrooms] => 1
[REAL_HOMES_property_garage] => 1
[REAL_HOMES_property_address] => Athwa Gate, Surat, Gujarat 395008, India
[REAL_HOMES_property_location] => 21.1852392,72.80947859999992
[REAL_HOMES_tour_video_url] => http://vimeo.com/70301553
[REAL_HOMES_featured] => 1
[REAL_HOMES_add_in_slider] => no
[REAL_HOMES_agents] => 110
[_dp_original] => 75
[REAL_HOMES_property_price_postfix] => Per Month
[_wp_old_slug] => 15421-southwest-39th-terrace-fl
[REAL_HOMES_tour_video_image] => 94
[REAL_HOMES_property_id] => Aagam003
[REAL_HOMES_property_size_postfix] => Sq Ft
[slide_template] => default
[REAL_HOMES_agent_display_option] => agent_info
[_edit_lock] => 1436890564:1
[_edit_last] => 1
[_thumbnail_id] => 894
[REAL_HOMES_slider_image] => 841
)
然后我用Php将这个array
编码为Json。
json_encode($result);
$result是结果数组
我使用AngularJS调用了一个Ajax请求,响应给了我下面的结果。
{"REAL_HOMES_gallery_slider_type":"thumb-on-right","REAL_HOMES_property_images":"94","REAL_HOMES_property_price":"3850","REAL_HOMES_property_size":"2800","REAL_HOMES_property_bedrooms":"2","REAL_HOMES_property_bathrooms":"1","REAL_HOMES_property_garage":"1","REAL_HOMES_property_address":"Athwa Gate, Surat, Gujarat 395008, India","REAL_HOMES_property_location":"21.1852392,72.80947859999992","REAL_HOMES_tour_video_url":"http:'/'/vimeo.com'/70301553","REAL_HOMES_featured":"1","REAL_HOMES_add_in_slider":"no","REAL_HOMES_agents":"110","_dp_original":"75","REAL_HOMES_property_price_postfix":"Per Month","_wp_old_slug":"15421-southwest-39th-terrace-fl","REAL_HOMES_tour_video_image":"94","REAL_HOMES_property_id":"Aagam003","REAL_HOMES_property_size_postfix":"Sq Ft","slide_template":"default","REAL_HOMES_agent_display_option":"agent_info","_edit_lock":"1436890564:1","_edit_last":"1","_thumbnail_id":"894","REAL_HOMES_slider_image":"841"}0
我不知道为什么结尾有一个零,即使我没有在响应中附加任何东西。我猜结果是一个Json字符串,所以我尝试将其转换为Json对象来使用它并从键中获取数据。我有其他Json响应是在[]
括号。但这个不是,可能是由于Json字符串响应末尾的0。
请帮帮我。谢谢。
这是wordpress和它的ajax系统的事情。如果你看一下文件wp-admin/admin-ajax.php,在文件的末尾有一个die(0)语句,这是罪魁祸首。
为了不运行该语句,您需要添加一个wp_die();