我構建解碼JSON文件天氣應用程序(在這裏找到:http://api.openweathermap.org/data/2.5/forecast?q=Helsinki&appid=77f5e3fbc99649054660f82f871220f4&units=metric)如何使用PHP導航JSON層次結構?
我遇到的問題,在我的PHP代碼導航JSON文件,以正確選擇tempature。
我需要做list->1->main->temp
但這會在PHP中引發一個數字錯誤。我如何正確設置導航?
echo "<form id='searchform' method='POST' action='https://projekt2-sofiamusick.c9users.io/wordpress/prognos/'>
Search: <input type='text' name='searchquery' placeholder='Search the forum' />
<input class='sendbutton_search' type='submit' name='search' value='>>' />
</form>";
if (isset($_POST['search'])){
$cityz = $_POST['searchquery'];
echo "<br>";
echo "<div id=apithing>";
$data = file_get_contents("http://api.openweathermap.org/data/2.5/forecast?q=$cityz&appid=77f5e3fbc99649054660f82f871220f4&units=metric");
$jsonObject = json_decode($data, JSON_NUMERIC_CHECK);
json_encode(array('list' => (int)$jsonObject));
$list = $jsonObject->list;
$number = $jsonObject->'1';
$mains = $jsonObject->main;
echo $mains;
嘗試:'list [0] - > main-> temp'列表將是一個數組 –