好的,我正在尝试使用 php 来编码一个 json 文件,我随后用它来使用 Polymaps 服务绘制地图。
我在从 Instagram API 编码我的 json 时遇到了麻烦——我可以做到,但我需要以这种特定方式嵌套结构。我的代码现在以这种格式对其进行编码:
[
{
"title":"some value",
"src":"some value",
"lat":"some value",
"lon":"some value"
},
...
等等等等。我需要格式来匹配更像这样的东西:
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"geometry":{
"coordinates":[
-94.34885,
39.35757
],
"type":"Point"
},
"properties":{
"latitude":39.35757,
"title":"Kearney",
"id":919,
"description":"I REALLY need new #converse, lol. I've had these for three years. So #destroyed ! :( Oh well. Can't wait to get a new pair and put my #rainbow laces through. #gay #gaypride #bi #proud #pride #colors #shoes #allstar #supporting ",
"longitude":-94.34885,
"user":"trena1echo5",
"image":"http://images.instagram.com/media/2011/09/09/ddeb9bb508c94f2b8ff848a2d2cd3ece_7.jpg",
"instagram_id":211443415
}
},
{
"type":"Feature",
"geometry":{
"coordinates":[
-0.09402781,
51.51512
],
"type":"Point"
},
"properties":{
"latitude":51.51512,
"title":"City Of London",
"id":918,
"description":"#destroyed",
"longitude":-0.09402781,
"user":"axxoul",
"image":"http://distillery.s3.amazonaws.com/media/2011/09/09/ffda47fb97924a41bc36b0b024fcdfad_7.jpg",
"instagram_id":211074717
}
},
...具有嵌套结构。我让 jquery 从 json 文件中读取数据,并编写了 php 脚本来制作 json ......这对我来说是最后一块拼图。