我正在尝试使用PHP的foreach()循环从Reddit JSON API中提取标题和URL。 Here is what the JSON outputs when used in print_r.
这是我到目前为止的代码......
$string_reddit = file_get_contents("http://reddit.com/hot.json");
$json = json_decode($string_reddit, true);
答案 0 :(得分:4)
$string_reddit = file_get_contents("http://reddit.com/hot.json");
$json = json_decode($string_reddit, true);
$children = $json['data']['children'];
foreach ($children as $child){
$title = $child['data']['title'];
$url = $child['data']['url'];
}