【发布时间】:2015-09-23 01:43:38
【问题描述】:
我有一个 JSON,我想使用 Javascript 读取项目内的标题和链接。
{
"rss": {
"version": "2.0",
"content": "http://purl.org/rss/1.0/modules/content/",
"channel": {
"title": " National",
"pubDate": "Mon, 06 Jul 2015 10:56:29 +1000",
"lastBuildDate": "Mon, 06 Jul 2015 10:56:29 +1000",
"generator": "news_national_3354",
"ttl": "5",
"item": [
{
"title": "Australia’s biggest housing demolition begins",
"link": "http://www.news.com.au/lifestyle/health/mr-fluffy-housing-demolitions-begin/story-fneuzlbd-1227430208115?from=public_rss",
},
{
"title": "Barnaby Joyce pulls out of Q&A",
"link": "http://www.news.com.au/national/barnaby-joyce-pulls-out-of-scheduled-qa-appearance/story-fncynjr2-1227429015164?from=public_rss",
},
{
"title": "Children who murder parents",
"link": "http://www.news.com.au/national/crime/one-parent-is-killed-a-month-by-their-child-crime-statistics-reveal/story-fns0kb1g-1227428117585?from=public_rss",
}
]
}
}
}
我不想使用 PHP。我正在从不同的域服务器读取 Xmls,我得到了Cross Domain Error。我找到了this 将 xml 转换为 JSON 的解决方案。我能够从不同的域读取 xml 并将其作为 JSON 获取。这个解决方案是否足够高效,可以在实时项目中使用,或者我不应该使用 Javascript 从不同的服务器获取 XML。请在这个问题上给我建议。谢谢
【问题讨论】:
-
JSONP 可能是您正在寻找的应对跨域访问的方法。
标签: javascript jquery json xml cross-domain