2012-06-10 2 views
1

다음 코드는 저에게 적합하지 않습니다. 난과 같이 넣으면JSON이 응답하지 않음

<?php 
$json_string = file_get_contents("http://api.wunderground.com/api/7ec5f6510a4656df/geolookup/forecast/q/40121 .json"); 
$parsed_json = json_decode($json_string); 
$temp = $parsed_json->{'forecast'}->{'date'}; 
echo "Current date is ${temp}\n"; 


?> 

그것은 작동 :

$temp = $parsed_json->{'location'}->{'city'}; 

내가 롤 여기에 놓친 거지 무슨

답변

3

이 있어야한다 :

$temp = $parsed_json->{'forecast'}->{'txt_forecast'}->{'date'}; 

을 JSON 객체를 보는 더 나은 방법을, this site 봐.

+0

'$ parsed_json-> forecast-> txt_forecast-> date;' –

+0

제목과 fcttext를 가져 오는 것은 어떻습니까? 나는 당신이 그들을 붙잡기 위해 보여준 것과 $ title = $ parsed_json -> { 'forecast'} -> { 'txt_forecast'} -> { 'forecastday'} -> { 'title'}; –

+0

@JuanMendes 필자는 PHP json 구문에 익숙하지 않아서 잠재적으로 옳을 수도 있습니다. 데이빗, 객체들을 순서대로 호출해야합니다. –

0

당신이 40121 .json" 실제로 공간을 상기 URL에 불필요한 공백이처럼 보이 끝은 무시 된 것 같다.

With spaces

No spaces

+0

실제로 유효한 주소입니다. 나는 그것에 갔다. –

+0

흠, Google 크롬이 나를 자동으로 포맷 한 것 같습니다. –