Theme NexT works best with JavaScript enabled

ShunNien's Blog

不積跬步,無以致千里;不積小流,無以成江海。

0%

RSS 轉換 Json 輸出

最近剛好需要串接其他資料的 RSS 來顯示資訊,以前是使用 Google Feed 提供的轉換服務,不過 2015 年的時候 Google 已經停止該服務,所以現在可以使用 RSS2Json 這個網站提供的服務。

URL

1
https://api.rss2json.com/v1/api.json

Method

GET

URL params

Name Required Type Description
rss_url Yes String, Escaped URL rss feed you want to convert to json, the url need to be escaped
api_key No String A valid api key.
order_by No String Order the results by chosen value, Possible values : pubDate, author or title.
order_dir No String Order direction of feed items to return, Possible values : asc or desc, Default value : desc.
count No Integer Count of feed items to return, default is 20 .
callback No Alphanumeric callback name if you want to use JSONP .

Sample Call

api call using jQuery.ajax()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$.ajax({
url: 'https://api.rss2json.com/v1/api.json',
method: 'GET',
dataType: 'json',
data: {
rss_url: 'https://news.ycombinator.com/rss',
api_key: '0000000000000000000000000000000000000000', // put your api key here
count: 2
}
}).done(function (response) {
if(response.status != 'ok'){ throw response.message; }

console.log('====== ' + response.feed.title + ' ======');

for(var i in response.items){
var item = response.items[i];
console.log(item.title);

}
});

拿 Blog 的 RSS 來轉換,如下
blog rss sample

參考資料

歡迎關注我的其它發布渠道