현재 날씨 가져오는 부분
$url = "https://api.openweathermap.org/data/2.5/forecast?lat=35.17332899587668&lon=129.13085319903072&lang=en&units=metric&appid=appkey"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); $jsondata = json_decode($response); echo ''; print_r($jsondata); echo '#'; echo '
'; 위와 같이 작업해서 웹에서 보면 아래와 같이 출력이 됩니다. 여기에서 첫번째 부분의 온도 [temp] => 24.44 를 가져오려고 하면 echo 어떻게 호출을 해야될까요? stdClass Object ( [cod] => 200 [message] => 0 [cnt] => 40 [list] => Array ( [0] => stdClass Object ( [dt] => 1654257600 [main] => stdClass Object ( [temp] => 24.44 [feels_like] => 24.11 [temp_min] => 19.43 [temp_max] => 24.44 [pressure] => 1011 [sea_level] => 1011 [grnd_level] => 1011 [humidity] => 45 [temp_kf] => 5.01 ) [weather] => Array ( [0] => stdClass Object ( [id] => 800 [main] => Clear [description] => clear sky [icon] => 01n ) ) [clouds] => stdClass Object ( [all] => 8 ) [wind] => stdClass Object ( [speed] => 5.79 [deg] => 36 [gust] => 9.08 ) [visibility] => 10000 [pop] => 0 [sys] => stdClass Object ( [pod] => n ) [dt_txt] => 2022-06-03 12:00:00 ) [1] => stdClass Object ( [dt] => 1654268400 [main] => stdClass Object ( [temp] => 21.1 [feels_like] => 20.91 [temp_min] => 18.18 [temp_max] => 21.1 [pressure] => 1012 [sea_level] => 1012 [grnd_level] => 1012 [humidity] => 63 [temp_kf] => 2.92 ) [weather] => Array ( [0] => stdClass Object ( [id] => 802 [main] => Clouds [description] => scattered clouds [icon] => 03n ) ) [clouds] => stdClass Object ( [all] => 35 ) [wind] => stdClass Object ( [speed] => 4.82 [deg] => 27 [gust] => 7.32 ) [visibility] => 10000 [pop] => 0 [sys] => stdClass Object ( [pod] => n ) [dt_txt] => 2022-06-03 15:00:00 )
댓글을 작성하려면 로그인이 필요합니다.
답변 2개
마르스컴퍼니
3년 전
$jsondata = json_decode($response);
$arr = json_decode($response, true);
echo $arr['list'][0]['main']['temp'];
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
3년 전
//print_r($jsondata);
echo $jsondata->list[0]->main->temp;
이러면 되지 않을까요?
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인전체 질문 목록
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
채택
답변대기
답변대기
답변대기
답변대기
채택
채택
답변대기