帮助构建JSON数据

时间:2011-05-27 15:56:44

标签: xml json jsonp

我正在使用以下xml结构在我的网站上创建xml feed,其中item部分循环多次,具体取决于从数据库返回的行数。

<?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 个答案:

答案 0 :(得分: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"
          } ]
     } ]
  }
}