I am writing an RSS feed (for fun) and was looking at the spec here.
我正在编写RSS提要(为了好玩),并在这里查看规范。
RSS is a dialect of XML. All RSS files must conform to the XML 1.0 specification, as published on the World Wide Web Consortium (W3C) website.
RSS是XML的一种方言。所有的RSS文件必须符合XML 1.0规范,如万维网联盟(W3C)网站上发布的。
Obviously this means that I am not serving 'pure' RSS if I choose the JSON option. That said, if I conform to the rest of the spec, is it likely that (customised) readers will be able to parse it?
显然,这意味着如果我选择JSON选项,我不会提供“纯”RSS。也就是说,如果我符合规范的其余部分,(定制的)读者有可能解析它吗?
To put it another way, if I conform to the spec, but using JSON instead of XML is it a usable RSS feed?
换句话说,如果我遵循规范,但是使用JSON而不是XML,这是一个可用的RSS提要吗?
edit I am not sure I made myself clear. There is no XML involved. I want to write something akin to RSS (which is XML) using JSON instead. Obviously the readers of such a feed would need to be written to understand the JSON format. I was wondering if this had been done already. Are there services that serve a feed this way? Are there programs that can aggregate/understand this format. Is the RSS spec (sans the XML part) a useful spec to conform to in this case?
编辑:我不太清楚我说的是什么。不涉及XML。我想用JSON编写一些类似RSS(即XML)的东西。显然,需要编写这样一个提要的读者来理解JSON格式。我在想这事是不是已经做过了。是否有服务以这种方式提供提要?是否有可以聚合/理解这种格式的程序。在这种情况下,RSS规范(不包括XML部分)是否值得遵循?
rg
rg
{
"title":"example.com",
"link":"http://www.example.com/",
"description":"Awesome news about junk",
"items":[
{
"title":"An article",
"link":"http://www.example.com/an-article",
"descrition":"Some sample text here",
"pubDate":"2008-10-27 11:06 EST",
"author":"example author",
},
{
"title":"Second",
"link":"http://www.example.com/Seond",
"descrition":"Some sample text here",
"pubDate":"2008-10-25 23:20 EST",
"author":"author mcauthor",
},
{
"title":"third article",
"link":"http://www.example.com/third-article",
"descrition":"Some sample text here",
"pubDate":"2008-10-25 23:18 EST",
"author":"some other author",
}
]
}
8 个解决方案
#1
14
I believe this has been done already.
我相信这已经实现了。
Take a look at this jQuery extension: jFeed - RSS/ATOM feed parser
看看这个jQuery扩展:jFeed - RSS/ATOM提要解析器。
jQuery.getFeed(options);
Options:
选项:
- url:
- url:
- data:
- 数据:
- success:
- 成功:
Example:
例子:
jQuery.getFeed({
url: 'rss.xml',
success: function(feed) {
alert(feed.title);
}
});
Note that in this case, 'feed' would be a javascript object. If you wanted to pass this using JSON, you can just use the javascript JSON utility.
注意,在这种情况下,'feed'将是一个javascript对象。如果您想要使用JSON传递它,您可以使用javascript JSON实用程序。
Example:
例子:
var myJSONText = JSON.stringify(feed);
#2
20
No, RSS is an XML-based format, and JSON is an different language rather than some kind of dialect. RSS readers won't understand JSON.
不,RSS是一种基于xml的格式,JSON是一种不同的语言,而不是某种方言。RSS阅读器无法理解JSON。
Your question is akin to asking 'Can I speak French in Chinese?'
你的问题类似于问“我能用中文说法语吗?”
#3
9
Is the RSS spec (sans the XML part) a useful spec to conform to in this case?
在这种情况下,RSS规范(不包括XML部分)是否值得遵循?
If you want to invent yet another syndication format, I recommend using Atom as a base. IMHO it has much cleaner, more consistent design, and has useful features like reliable updates of past items, makes distinction between summaries and full content, etc.
如果您想发明另一种联合格式,我建议使用Atom作为基础。IMHO的设计更简洁、更一致,并且有一些有用的特性,比如对过去项目的可靠更新,可以区分摘要和完整内容等。
I was wondering if this had been done already.
我在想这事是不是已经做过了。
Flickr has JSON output format. They even have lolcode feed.
Flickr有JSON输出格式。他们甚至有lolcode feed。
#4
3
Json.NET - http://james.newtonking.com/projects/json-net.aspx - has support to convert any XML document to JSON.
Json。NET - http://james.newtonking.com/projects/json-net.aspx -支持将任何XML文档转换为JSON。
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"<?xml version=""1.0"" standalone=""no""?>
<root>
<person id=""1"">
<name>Alan</name>
<url>http://www.google.com</url>
</person>
<person id=""2"">
<name>Louis</name>
<url>http://www.yahoo.com</url>
</person>
</root>");
string jsonText = JavaScriptConvert.SerializeXmlNode(doc);
//{
// "?xml": {
// "@version": "1.0",
// "@standalone": "no"
// },
// "root": {
// "person": [
// {
// "@id": "1",
// "name": "Alan",
// "url": "http://www.google.com"
// },
// {
// "@id": "2",
// "name": "Louis",
// "url": "http://www.yahoo.com"
// }
// ]
// }
//}
XmlDocument newDoc = (XmlDocument)JavaScriptConvert.DeerializeXmlNode(jsonText);
Assert.AreEqual(doc.InnerXml, newDoc.InnerXml);
#5
3
You're right that the client reading the feed would have to have custom support for whatever the particulars of your JSON were. So you'd either need to make a custom feed reader to consume that information, or someone would have to propose a JSON feed standard, and it'd have to be widely adopted.
您是对的,读取提要的客户端必须对JSON的任何细节提供自定义支持。因此,要么需要定制提要阅读器来使用这些信息,要么必须有人提出JSON提要标准,而且必须得到广泛采用。
Well, I think your desires have finally been met, friend!
我想你的愿望终于实现了,朋友!
Take a look at JSON Feed. As of this writing it's only about a week old, but it's already picking up steam, having been supported now by Feedly, Feedbin, News Explorer, NewsBlur, and more being added all the time.
看看JSON提要。到本文写作之时,它才发布了一个星期,但它已经开始流行起来了。Feedly、Feedbin、News Explorer、NewsBlur和更多内容都在不断被添加。
If I had to pick a standard to use when generating a JSON version of RSS, I'd pick JSON Feed for sure.
如果在生成JSON版本的RSS时必须选择一个标准,我肯定会选择JSON提要。
#6
2
There are a bunch of different ways to serialize RSS into JSON. All of them work pretty much the same way: the elements and attributes become property names, the values become property values, etc. See Piyush Shah's technique, for example, which is a .NET implementation.
有很多不同的方法可以将RSS序列化为JSON。它们的工作方式几乎都是一样的:元素和属性变成了属性名,值变成了属性值,等等。
Transforming arbitrary XML to JSON using XSLT is simple enough that you can find a half-dozen examples of it on Google.
使用XSLT将任意XML转换成JSON非常简单,您可以在谷歌上找到它的六个示例。
As long as this is done consistently, JavaScript that can process an object model designed to replicate the data structure of the RSS specification should be able to handle the object model that the JSON deserializes into.
只要这是一致的,JavaScript就可以处理设计用来复制RSS规范的数据结构的对象模型,它应该能够处理JSON反序列化为的对象模型。
Who are you planning to send this JSON to? That's the real question.
您打算将这个JSON发送给谁?这是真正的问题。
#7
1
Well, if you are developing some javascript app you might want to get any RSS feeds as JSON to overcome cross-domain querying issue. There is a reliable Google provided solution that converts about any RSS to JSON. For jQuery lover's there is a universal RSS to JSON converter plugin.
如果您正在开发一些javascript应用程序,您可能希望获得任何RSS提要作为JSON,以克服跨域查询问题。有一个可靠的谷歌提供的解决方案,可以将任何RSS转换为JSON。对于jQuery爱好者,有一个通用的RSS到JSON转换器插件。
Example:
例子:
$.jGFeed('http://twitter.com/statuses/user_timeline/26767000.rss',
function(feeds){
// feeds is a javascript object with RSS content
}, 10);
#8
0
I know this is a fairly old question, and maybe irrelevant now.
我知道这是一个相当古老的问题,现在可能已经无关紧要了。
However. I would suggest anyone looking to publish a RSS-like feed in JSON should use a new format that is rapidly gaining adoption; JSONFeed (https://jsonfeed.org).
然而。我建议任何希望在JSON中发布类似rss的提要的人应该使用一种正在迅速被采用的新格式;JSONFeed(https://jsonfeed.org)。
#1
14
I believe this has been done already.
我相信这已经实现了。
Take a look at this jQuery extension: jFeed - RSS/ATOM feed parser
看看这个jQuery扩展:jFeed - RSS/ATOM提要解析器。
jQuery.getFeed(options);
Options:
选项:
- url:
- url:
- data:
- 数据:
- success:
- 成功:
Example:
例子:
jQuery.getFeed({
url: 'rss.xml',
success: function(feed) {
alert(feed.title);
}
});
Note that in this case, 'feed' would be a javascript object. If you wanted to pass this using JSON, you can just use the javascript JSON utility.
注意,在这种情况下,'feed'将是一个javascript对象。如果您想要使用JSON传递它,您可以使用javascript JSON实用程序。
Example:
例子:
var myJSONText = JSON.stringify(feed);
#2
20
No, RSS is an XML-based format, and JSON is an different language rather than some kind of dialect. RSS readers won't understand JSON.
不,RSS是一种基于xml的格式,JSON是一种不同的语言,而不是某种方言。RSS阅读器无法理解JSON。
Your question is akin to asking 'Can I speak French in Chinese?'
你的问题类似于问“我能用中文说法语吗?”
#3
9
Is the RSS spec (sans the XML part) a useful spec to conform to in this case?
在这种情况下,RSS规范(不包括XML部分)是否值得遵循?
If you want to invent yet another syndication format, I recommend using Atom as a base. IMHO it has much cleaner, more consistent design, and has useful features like reliable updates of past items, makes distinction between summaries and full content, etc.
如果您想发明另一种联合格式,我建议使用Atom作为基础。IMHO的设计更简洁、更一致,并且有一些有用的特性,比如对过去项目的可靠更新,可以区分摘要和完整内容等。
I was wondering if this had been done already.
我在想这事是不是已经做过了。
Flickr has JSON output format. They even have lolcode feed.
Flickr有JSON输出格式。他们甚至有lolcode feed。
#4
3
Json.NET - http://james.newtonking.com/projects/json-net.aspx - has support to convert any XML document to JSON.
Json。NET - http://james.newtonking.com/projects/json-net.aspx -支持将任何XML文档转换为JSON。
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"<?xml version=""1.0"" standalone=""no""?>
<root>
<person id=""1"">
<name>Alan</name>
<url>http://www.google.com</url>
</person>
<person id=""2"">
<name>Louis</name>
<url>http://www.yahoo.com</url>
</person>
</root>");
string jsonText = JavaScriptConvert.SerializeXmlNode(doc);
//{
// "?xml": {
// "@version": "1.0",
// "@standalone": "no"
// },
// "root": {
// "person": [
// {
// "@id": "1",
// "name": "Alan",
// "url": "http://www.google.com"
// },
// {
// "@id": "2",
// "name": "Louis",
// "url": "http://www.yahoo.com"
// }
// ]
// }
//}
XmlDocument newDoc = (XmlDocument)JavaScriptConvert.DeerializeXmlNode(jsonText);
Assert.AreEqual(doc.InnerXml, newDoc.InnerXml);
#5
3
You're right that the client reading the feed would have to have custom support for whatever the particulars of your JSON were. So you'd either need to make a custom feed reader to consume that information, or someone would have to propose a JSON feed standard, and it'd have to be widely adopted.
您是对的,读取提要的客户端必须对JSON的任何细节提供自定义支持。因此,要么需要定制提要阅读器来使用这些信息,要么必须有人提出JSON提要标准,而且必须得到广泛采用。
Well, I think your desires have finally been met, friend!
我想你的愿望终于实现了,朋友!
Take a look at JSON Feed. As of this writing it's only about a week old, but it's already picking up steam, having been supported now by Feedly, Feedbin, News Explorer, NewsBlur, and more being added all the time.
看看JSON提要。到本文写作之时,它才发布了一个星期,但它已经开始流行起来了。Feedly、Feedbin、News Explorer、NewsBlur和更多内容都在不断被添加。
If I had to pick a standard to use when generating a JSON version of RSS, I'd pick JSON Feed for sure.
如果在生成JSON版本的RSS时必须选择一个标准,我肯定会选择JSON提要。
#6
2
There are a bunch of different ways to serialize RSS into JSON. All of them work pretty much the same way: the elements and attributes become property names, the values become property values, etc. See Piyush Shah's technique, for example, which is a .NET implementation.
有很多不同的方法可以将RSS序列化为JSON。它们的工作方式几乎都是一样的:元素和属性变成了属性名,值变成了属性值,等等。
Transforming arbitrary XML to JSON using XSLT is simple enough that you can find a half-dozen examples of it on Google.
使用XSLT将任意XML转换成JSON非常简单,您可以在谷歌上找到它的六个示例。
As long as this is done consistently, JavaScript that can process an object model designed to replicate the data structure of the RSS specification should be able to handle the object model that the JSON deserializes into.
只要这是一致的,JavaScript就可以处理设计用来复制RSS规范的数据结构的对象模型,它应该能够处理JSON反序列化为的对象模型。
Who are you planning to send this JSON to? That's the real question.
您打算将这个JSON发送给谁?这是真正的问题。
#7
1
Well, if you are developing some javascript app you might want to get any RSS feeds as JSON to overcome cross-domain querying issue. There is a reliable Google provided solution that converts about any RSS to JSON. For jQuery lover's there is a universal RSS to JSON converter plugin.
如果您正在开发一些javascript应用程序,您可能希望获得任何RSS提要作为JSON,以克服跨域查询问题。有一个可靠的谷歌提供的解决方案,可以将任何RSS转换为JSON。对于jQuery爱好者,有一个通用的RSS到JSON转换器插件。
Example:
例子:
$.jGFeed('http://twitter.com/statuses/user_timeline/26767000.rss',
function(feeds){
// feeds is a javascript object with RSS content
}, 10);
#8
0
I know this is a fairly old question, and maybe irrelevant now.
我知道这是一个相当古老的问题,现在可能已经无关紧要了。
However. I would suggest anyone looking to publish a RSS-like feed in JSON should use a new format that is rapidly gaining adoption; JSONFeed (https://jsonfeed.org).
然而。我建议任何希望在JSON中发布类似rss的提要的人应该使用一种正在迅速被采用的新格式;JSONFeed(https://jsonfeed.org)。