2011-05-27 100 views
1

我正在使用以下xml結構在我的網站上創建xml訂閱源,其中項目部分根據數據庫返回的行數循環多次。幫助構建JSON數據

<?xml version="1.0" encoding="utf-8"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
    <channel> 
     <title>title goes here</title> 
     <link>link goes here</link> 
     <atom:link href="url goes here" rel="self" type="application/rss+xml" /> 
     <description>description goes here</description> 
     <item> 
      <title>title goes here</title> 
      <link>url goes here</link> 
      <guid>id goes here</guid> 
      <pubDate>data goes here</pubDate> 
      <description>description goes here</description> 
     </item> 
    </channel> 
</rss> 

我現在有需要使用jsonp。構建json數據以json形式返回上述數據的最佳方式是什麼?

回答

1

這是我會怎麼構建它:

{ 
    "rss": { 
    "channels" : [ 
     { 
     "title" : "title goes here", 
     "link": "link goes here", 
     "description": "description goes here", 
     "items" : [ 
      { 
      "title": "title goes here", 
      "link": "url goes here", 
      "guid": "id goes here", 
      "pubDate": "data goes here", 
      "description": "description goes here" 
      } ] 
    } ] 
    } 
}