【发布时间】:2011-03-20 19:12:04
【问题描述】:
我尝试使用 JSON 解码来获取 youtube API 提要。但是,当我将 JSON 结果粘贴到 http://www.jsonlint.com/ 时,我注意到类似
"media$group": {
"media$category": [
不幸的是,一些符号被 php 拒绝了。这是我的代码,我试图删除这个$ 符号,但可能没有成功。我该如何解决?
$url = 'http://gdata.youtube.com/feeds/api/videosq=football&orderby=published&v=2&alt=json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
$body1 = curl_exec($ch);
$body = str_replace('$','', $body1);
curl_close($ch);
$data = json_decode($body);
foreach ($data->feed->entry as $result) {
...
}
【问题讨论】:
-
json_decode不受字符串中的$影响。您意识到显示的 URL 给出了Invalid request URI错误吗? -
@mario,我想获取媒体描述。如果我忽略
$,请使用echo $result->mediagroup->mediadescription;,它会回调Catchable fatal error: Object of class stdClass could not be converted to string in...