我正在编写一个wordpress循环,它获取多个post并在基于php的数组中输出post自定义字段GeoJson coordinates数组。
$sFeatureCoordinates
变量。
[
[
-0.7332730293273926,
51.89886634382943
],
[
-0.7326534390449524,
51.89770778622719
],
[
-0.7318434119224548,
51.898079355455344
],
[
-0.7332730293273926,
51.89886634382943
]
]
json_encode
格式化数组。
$arr = [
'type' => 'FeatureCollection',
'features' => []
];
// loop through each post
while($oQuery->have_posts()): $oQuery->the_post();
// grab our type and coordinates
$sFeatureType = get_field('geojson_feature_type');
$sFeatureCoordinates = get_field('geojson_feature_coordinates');
// add this to our features
$arr['features'][] = [
'type' => 'Feature',
'properties' => [
'id' => get_the_id(),
'name' => get_the_title()
],
'geometry' => [
'type' => $sFeatureType,
'coordinates' => [
[ preg_replace('/\s+/', '', $sFeatureCoordinates) ]
]
]
];
endwhile;
$json = json_encode($arr);
下面是从上面的数组输出的json示例
http://myjson.com/pssis
我的问题是
coordinates
当它被编码的时候会被用引号括起来。
有什么办法能阻止我的行为吗
将内容用引号括起来
json\ U编码
非常感谢