dongmeixian9665 2013-09-23 18:04
浏览 106
已采纳

你能做一个$ json = file_get_contents($ url); 在已使用$ json = file_get_contents($ url);的foreach语句中? [关闭]

$url = "www.test.com"
$json = file_get_contents($url);
$data = json_decode($json);

foreach($data as $mydata) {

    $id = $mydata->id;

        $url2 = "www.test.com/$id";
        $json2 = file_get_contents($url2);
        $data2 = json_decode($json2);
        var_dump($data2); // seems to always be null?? :(

            foreach($data2 as $mydata2) {

                   .............
                }
}

the error I get is Warning: Invalid argument supplied for foreach() which is because data2 is not an array....

Guessing I can't do file_get_contents() stacked like I am. Is there a way around this?

  • 写回答

2条回答 默认 最新

  • doormen2014 2013-09-23 18:12
    关注

    URL isn't returning valid JSON.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?