【发布时间】:2013-08-17 13:11:03
【问题描述】:
我正在尝试解析来自各种来源的 rss 提要,其中一个来源是:http://feeds.feedburner.com/DiscoveryNews-Top-Stories
但是这个来源给了我一些奇怪的 json 数据,像这样:
"item": [
{
"title": [
"Snazzy Science Photos of the Week (August 10-16)",
{
"type": "html",
"content": "Snazzy Science Photos of the Week (August 10-16)"
}
],
"description": [
"Glowing rabbits, treasure-hunting badgers and a case of mistaken UFO identity help round out this week's photos.<img src=\"http://feeds.feedburner.com/~r/DiscoveryNews-Top-Stories/~4/S6Urfvdw2DQ\" height=\"1\" width=\"1\"/>",
{
"type": "html",
"content": "Glowing rabbits, treasure-hunting badgers and a case of mistaken UFO identity help round out this week's photos."
}
],
目前,我正在使用以下代码来获取帖子的标题:
if(isset($jit->title->content)){
$title = $decoded_json->query->results->item->title->content;
}else{
$title = $decoded_json->query->results->item->title;
}
但当我尝试解析 Discovery 新闻提要时,上述代码失败。请帮忙?
[编辑]: 我正在使用 YQL 从源代码中获取等效的 JSON。这是 link
【问题讨论】:
-
我没有看到任何 JSON,只有 XML 可用。
-
@RajatSaxena 你能展示(jsfiddle?)你是如何使用 YQL/json 提要的吗?
-
我只从 PHP 解析它,我没有使用 javascript。另外,我只粘贴了我在我的问题中使用的 PHP 代码。