我有两个标记为sample.json和sample2.json的json文件。他们都拉动略有不同的数据,但格式应该是相似的。当我在sample1.json上运行我的脚本时,它可以工作。当我在sample.json运行我的脚本失败并称线141和169无效的foreach参数
线路141码无效的foreach参数在这里:
foreach($posts as &$entry){
$mod = new modifier($entry); //create modifier object
$result = $mod->getResult(); //gives parsed text back
$entry['mod-post'] = $result;
$usr = $entry['user']['screen_name']; //mod the usr as well while we are at it to give a new usr
$usr = '@' . $usr;
$entry['mod-usr'] = $usr;
}
,当我读出的数据在它有作为
$datafile = 'data/sample.json';
//open up datafile created through search
$myfile = fopen($datafile, 'r') or die('Unable to open file!!!');
$d = fread($myfile, filesize($datafile));
//file already formatted as json
$data = array();
$data = json_decode($d, true);
$posts = $data["statuses"]; //make easier to access later
fclose($myfile);//close file
基于我所看到的,我认为这个问题是第二JSON文件没有被正确读取。这就是说,当我上传我的文件到jsonlint或任何json检查器时,它给了我一个无效的json for BOTH文件(或者我不知道为什么,我从twitter中提取数据,所以它应该没问题)。
如果您有时间快速浏览一下,我已经链接了json文件。
https://www.dropbox.com/s/3zqwqtbav7ii9if/sample1.json?dl=0
和
https://www.dropbox.com/s/7xh94csike6ucqc/sample.json?dl=0
即使你可以给我一个提示,是什么问题是,而且为什么我的程序可以在sample1.json运行,但没有品尝.json会有帮助。
更新:我一直在检查JSON文件和JSON Lint给了sample1一个有效的响应。看起来像json.parser.online.fr/不工作!!!我会继续调查! – and0rsk 2014-08-31 06:19:27