我有一些編碼的JSON這樣的:解碼JSON每個數組到PHP
[
{"title":"root", "link":"one"},
{"title":"branch", "link":"two"},
{"title":"leaf", "link":"three"}
]
我想這解碼JSON到PHP輸出,如:
title || link
root || one
branch || two
leaf || three
我試過,但不起作用:
$list = json_decode($json);
foreach ($list as $list => $value) {
echo $list->title;
echo $list->link;
}
允許的,但我想編碼這個連結http:/ /penanggulangankrisis.kemkes.go.id/ipaddress/api_ip.php和它說無效的foreach參數 我使用json_decode(file_get_contents($ url2),true); and $ url2 =「http://penanggulangankrisis.kemkes.go.id/ipaddress/api_ip.php」; –
@dennisramli var_dump file_get_contents,結果是什麼? 「空值」? – DevNiels
不,結果不爲空@DevNiels –