我调用OneMap.sg API
$url='http://www.onemap.sg/API/Services.svc/ga?token=**************&sv=575565';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($curl);
var_dump(curl_error($curl));
curl_close($curl);
var_dump($resp);
并得到以下回应,其工作完美。
string(0) "" string(109) "{"GeoAddrInfo":[{"BLDG_NAME":"BISHAN PARK SECONDARY SCHOOL","HBRN":"2 SIN MING WALK","PostalCode":"575565"}]}"
现在我想从上面的响应结果中得到值。比如。
{
BLDG_NAME = "BISHAN PARK SECONDARY SCHOOL";
HBRN = "2 SIN MING WALK";
}
答案 0 :(得分:2)
这是JSON,所以你可以
$resp = json_decode($resp);
echo $resp->GeoAddrInfo[0]->BLDG_NAME;
echo $resp->GeoAddrInfo[0]->HBRN;