file_get_contents没有得到json

时间:2015-03-27 18:00:56

标签: php json

我有PHP应该从postcodes api(http://postcodes.io/)获取JSON对象,但它似乎没有工作。

if(isset($_POST["postcode"])){

    $json = file_get_contents('api.postcodes.io/postcodes/'.$_POST["postcode"]);
    $json_data = json_decode($json, true);
    echo "My token: ". $json_data["status"];

}

$json_data["status"];不回应任何内容。

例如当$_POST["postcode"]等于“IP12 2UH”时,应返回以下内容:

{
    "status": 200,
    "result": {
        "postcode": "IP12 2UH",
        "quality": 1,
        "eastings": 633715,
        "northings": 253024,
        "country": "England",
        "nhs_ha": "East of England",
        "longitude": 1.41299500121177,
        "latitude": 52.126073695307,
        "parliamentary_constituency": "Suffolk Coastal",
        "european_electoral_region": "Eastern",
        "primary_care_trust": "Suffolk",
        "region": "East of England",
        "lsoa": "Suffolk Coastal 007G",
        "msoa": "Suffolk Coastal 007",
        "nuts": null,
        "incode": "2UH",
        "outcode": "IP12",
        "admin_district": "Suffolk Coastal",
        "parish": "Suffolk Coastal",
        "admin_county": "Suffolk",
        "admin_ward": "Rendlesham",
        "ccg": "NHS Ipswich and East Suffolk",
        "codes": {
            "admin_district": "E07000205",
            "admin_county": "E10000029",
            "admin_ward": "E05007216",
            "parish": "E04009449",
            "ccg": "E38000086"
        }
    }
}

1 个答案:

答案 0 :(得分:2)

您需要在网址

中添加http://