php JSON decode with Twitter geo/search


php JSON decode with Twitter geo/search

如何从推特地理/搜索获取坐标?JSON 树中有四个坐标,但结果是数组。如何?谢谢。

API URL : https://api.twitter.com/1/geo/search.json?query=tokyo//での取得結果

json[result]['places']['0']['name']=Tokyo
json[result]['places']['0']['bounding_box']['type']=Polygon
json[result]['places']['0']['bounding_box']['coordinates'][0][0]=Array  //Array data.

杰伦斯树

{
    "result": {
        "places": [
            {
                "name": "Tokyo",
                "bounding_box": {
                    "type": "Polygon",
                    "coordinates": [
                        [
                            [
                                138.942806388889,
                                24.222885
                            ],
                            [
                                142.248202222222,
                                24.222885
                            ],
                            [
                                142.248202222222,
                                35.8986897222222
                            ],
                            [
                                138.942806388889,
                                35.8986897222222
                            ]
                        ]
                    ]
                },
       ... // a long tree, something not important, hiden...

更新

<?php
header('Content-type:text/html; charset=utf-8');
$url = "https://api.twitter.com/1/geo/search.json?query=tokyo";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: api.twitter.com'));
$body = curl_exec($ch);
curl_close ($ch);
$data = json_decode($body, true);
foreach ($data['result']['places'] as $data) {
    echo $data['bounding_box']['coordinates']['0']['0'].'<br />'; //array
}
?>

如果你有JSON内容,你可以使用json_decode((函数 - 它会返回你可以读取的漂亮数组。

http://php.net/manual/en/function.json-decode.php