Answer the question
In order to leave comments, you need to log in
Can't output a specific string in json?
{"cod":"200","message":0.0021,"cnt":1,"list":[{"dt":1533135600,"main":{"temp":27.88,"temp_min":26.74,"temp_max":27.88,"pressure":1017.51,"sea_level":1036.77,"grnd_level":1017.51,"humidity":53,"temp_kf":1.13},"weather":[{"id":800,"main":"Clear","description":"ясно","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":1.97,"deg":19.0015},"sys":{"pod":"d"},"dt_txt":"2018-08-01 15:00:00"}],"city":{"id":524901,"name":"Moscow","coord":{"lat":55.7507,"lon":37.6177},"country":"RU","population":1000000}}
Answer the question
In order to leave comments, you need to log in
Weather you have an array. You missed the index call. This is how it outputs:
<?php
$data = json_decode('{"cod":"200","message":0.0021,"cnt":1,"list":[{"dt":1533135600,"main":{"temp":27.88,"temp_min":26.74,"temp_max":27.88,"pressure":1017.51,"sea_level":1036.77,"grnd_level":1017.51,"humidity":53,"temp_kf":1.13},"weather":[{"id":800,"main":"Clear","description":"ясно","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":1.97,"deg":19.0015},"sys":{"pod":"d"},"dt_txt":"2018-08-01 15:00:00"}],"city":{"id":524901,"name":"Moscow","coord":{"lat":55.7507,"lon":37.6177},"country":"RU","population":1000000}}');
?>
<?php foreach($data->list as $list): ?>
<?= $list->main->temp ?> Значение выводит
<?php foreach($list->weather as $l): ?>
<?= $l->icon ?> Значение невыводит
<?php endforeach; ?>
<?php endforeach; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question