-2
我的问题是加载一个JSON文件到我的PHP页面。使用XML/RSS我没有问题,并且在JavaScript中我也成功了,但是对于这个学校项目,我需要在PHP中加载JSON数据。解析JSON并通过它循环与PHP
{"tvshows":[
{
"showname":"Parenthood ",
"date":"2014-12-28",
"fullTitle":"Parenthood (2010) 2x10 \"Happy Thanksgiving \"",
"img":"http:\/\/zapp.trakt.us\/images\/episodes\/117-2-10.jpg?4"
},
{
"showname":"Parenthood ",
"date":"2014-12-28",
"fullTitle":"Parenthood (2010) 2x11 \"Damage Control\"",
"img":"http:\/\/zapp.trakt.us\/images\/episodes\/117-2-11.jpg?4"
},
{
"showname":"Benched ",
"date":"2014-12-27",
"fullTitle":"Benched 1x09 \"A New Development\"",
"img":"http:\/\/zapp.trakt.us\/images\/episodes\/33221-1-9.jpg?3"
}
]
}
当我使用这个PHP代码,没有看到一个输出:
$string = file_get_contents("url");
$json = json_decode($string, true);
print_r($json);
之后,我想通过电视节目走路,显示showname值。我应该怎么做?
kan您向我们展示var_dump($ string)以确保其有效的json? – Richard87 2015-01-04 13:35:29