json_decode 使用 PHP、NFL API 返回 null
由于某种原因 json_decode 返回 NULL 和有效的 JSON。
json 位于此处: http://www.nfl.com/liveupdate/scorestrip/scorestrip .json
我正在获取页面的文件内容(file_get_contents),然后在其上运行 json_decode 。
还尝试了魔术引号的stripslashes b/c。
提前致谢, 菲尔
$json = file_get_contents('http://www.nfl.com/liveupdate/scorestrip/scorestrip.json');
var_dump(json_decode($json));
For some reason json_decode is returning NULL with valid JSON.
The json is located here: http://www.nfl.com/liveupdate/scorestrip/scorestrip.json
I am getting the file contents of the page (file_get_contents) and then running json_decode on it.
Also tried stripslashes b/c of magic quotes.
Thanks in advance,
Phil
$json = file_get_contents('http://www.nfl.com/liveupdate/scorestrip/scorestrip.json');
var_dump(json_decode($json));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
空数组元素是无效的 JSON,即多个逗号之间没有值
您可以尝试在多个逗号之间插入空字符串(感谢 hakre),即
我不知道这是否会影响您继续使用数据的能力
The empty array elements are invalid JSON, ie the multiple commas with no values between
You could try inserting empty strings between multiple commas (thanks hakre), ie
I don't know if this messes up your ability to continue using the data though
我得出了和 Phil 相同的结论,但我花了大约 5 分钟的时间。 :)
但是,我注意到他的输出有一个问题......它正在删除一个字段。
我不喜欢在正则表达式中进行这种模式检测,只是因为我认为它更难维护。在本例中,我只是通过 while 循环运行它。
我确信菲尔可以想出一个合适的正则表达式,但这个解决方案将保持正确的条目数和条目数。他们的顺序位置。
I came the same conclusion as Phil, but it took me about 5 minutes longer. : )
However, I noticed a problem in his output... it is dropping a field.
I don't like doing this kind of pattern detection in RegEx, only because I think it is harder to maintain. In this case, I just run it through a while loop.
I'm sure Phil can come up with a proper RegEx, but this solution will maintain the right # of entries & their ordinal positions.
对于任何关注 2014 年的人。新的 feed 数据链接应该是:
http://www.nfl .com/liveupdate/scores/scores.json
For anyone looking in 2014. The new feed data link should be:
http://www.nfl.com/liveupdate/scores/scores.json