PHP数组到JSON,如何摆脱一些双引号? [英] PHP Array to json, how to get rid of some double quotes?
本文介绍了PHP数组到JSON,如何摆脱一些双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将php数组编码为json时,我遇到了一个小而奇怪的问题。
I have a small but weird problem while encoding php arrays to json.
我需要防止array()在特定值周围添加双引号。
I need to prevent array() from adding double quotes around specific values.
这是php数组:
$coordinates="[".$row["lat"].",".$row["lng"]."]";
$egUser=array(
"geometry"=>array(
"type"=>"$type",
"coordinates"=>$coordinates
),
"type2"=>"$type2",
"id"=>$id
);
$arrayjson[]=$egUser;
使用json_encode返回以下json:
Wich return the following json with json_encode :
var member = {
"type": "FeatureCollection",
"features": [{
"geometry": {
"type": "Point",
"coordinates": "[46.004028,5.040131]"
},
"type2": "Feature",
"id": "39740"
}]
};
如您所见,坐标包裹在双引号内>
As you can see the coordinates are wrapped inside double quote >
"coordinates": "[46.004028,5.040131]"
如何删除这些引号?我需要以下内容代替>
How do I get rid of these quotes ? I need to have the following instead >
"coordinates": [46.004028,5.040131]
我有点困惑,所以欢迎您提供任何帮助:)
谢谢!
I'm a bit confuse so any help is welcome :) Thank you !
推荐答案
那是因为 $ coordinates
的类型为String。
Thats because $coordinates
is of type String.
$coordinates="[".$row["lat"].",".$row["lng"]."]";
创建 $ coordinates
$coordinates = array($row["lat"],$row["lng"]);
这篇关于PHP数组到JSON,如何摆脱一些双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文