当我在页面加载时将 JSON 数据视为警报时,我看到:
[
"Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery",
37.69603499999999,
-79.17580859999998,
"<div id=\"post-45\"><a href=\"http://localhost/jhtwp/business/ankida-ridge-vineyards-the-vrooman-family-vineyard-winery/\">Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery</a></div>"
]
它通过 JSONlint。然而,在我的源数据中,我看到了这一点:
/* <![CDATA[ */
var busipress_map_vars = [];
busipress_map_vars = {"default_map_icon":"http:\/\/localhost\/jhtwp\/wp-content\/plugins\/busipress\/img\/red-dot.png","default_map_icon_width":32,"default_map_icon_height":32,"active_map_icon":"http:\/\/localhost\/jhtwp\/wp-content\/plugins\/busipress\/img\/blue-dot.png","active_map_icon_width":32,"active_map_icon_height":32,"map_icon_shadow":"http:\/\/localhost\/jhtwp\/wp-content\/plugins\/busipress\/img\/msmarker.shadow.png","map_icon_shadow_width":59,"map_icon_shadow_height":32,"center_lat":-34.397,"center_long":150.644,"path_start":"35.7719444, -78.6388889","path_end":"32.7763889, -79.9311111","locations":"[\"Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery\",37.69603499999999, -79.17580859999998, \"<div id=\\\"post-45\\\"><a href=\\\"http:\/\/localhost\/jhtwp\/business\/ankida-ridge-vineyards-the-vrooman-family-vineyard-winery\/\\\">Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery<\/a><\/div>\"]"};;
/* ]]> */
</script>
这是转义双引号(那里还有一些其他数据可以正常工作)。我有以下生成每个位置的函数:
function busipress_business_teaser($echo = true, $zindex) {
$location = get_field('address');
$location_array = explode(',',$location['coordinates']);
ob_start();
echo '["';
echo get_the_title();
echo '",';
echo $location_array[0] . ', ';
echo $location_array[1] . ', ';
echo '"<div ';
echo 'id=\"post-'.get_the_ID().'\">';
echo '<a href=\"'.get_permalink().'\">';
echo get_the_title();
echo '</a>';
echo '</div>"';
echo ']';
$display = ob_get_contents();
ob_end_clean();
if($echo) {
echo $display;
}
else {
return $display;
}
}
我是否以错误的方式创建这些数据?将此与 Google Maps API v3 一起使用。谢谢!