2014-03-07 39 views
0

以前,我是用XML來存儲我的應用程序用來對付播客信息。然而,使用解析器的複雜性使我從XML轉換到JSON以及其他一些原因。移動到JSON,我會轉換是正確的?

這裏是我的XML看起來像什麼:

<?xml version="1.0" encoding="utf-8"?> 
<show-list count="23"> 
    <show> 
     <title>TQA Weekly</title> 
     <description> 
      <![CDATA[ 
      Technology Show, dedicated to those who wish to learn about new electronics that they have bought, or will buy soon. 
      We will explaining in each episode new ways of doing things like protecting your identity online, file backup and storage, encryption, using email wisely, and each show we will be giving you new tools to do so. 
      You may visit our web-site for show notes, lists of software, links to sites, other suggested web-sites, or to send e-mails to Steve Smith with questions, comments or concerns. 
      ]]> 
     </description> 
     <host>Steve Smith</host> 
     <logo>http://images.tqaweekly.com/tqa-weekly-logo.png</logo> 
     <feed>http://feeds.podtrac.com/tTKj5t05olM$</feed> 
    </show> 
<!-- more shows --> 

,這裏是我的JSON的樣子:

{ 
    "count" : 23; 
    [ 
     "show" : { 
        "title" : "TQA Weekly", 
        "description" : "Technology show", 
        "host" : "Steve Smith", 
        "logo" : "http://images.tqaweekly.com/tqa-weekly-logo.png", 
        "feed" : "http://feeds.podtrac.com/tTKj5t05olM$" 
       }, 

     "show" : { 
        "title" : "TWiT", 
        "description" : "This Week In Tech", 
        "host" : "Sarah Lane, etc", 
        "logo" : "http://logo/url", 
        "feed" : "http://feed/url" 
       } 

     // more shows 
    ] 
} 

我的問題是:我已做得正確,從XML轉換爲JSON ?目的是表示JSON相同的信息。

我相信,我和別人一起做語法錯誤。請把它們指出來。我在JSON

回答

1

好一個新手,這不是有效的JSON(因爲你可以看到,當您嘗試解析它),所以沒有。

例如:

  • "count" : 23後分號是錯誤的(它應該是一個逗號),
  • 有一個列表之後,其中它不應該是(應該有之前的標識符)
  • 該列表包含像字典那樣的元素,因此這些是非法的
  • 如果該列表是字典,則它將是非法的,因爲它包含兩次相同的密鑰。

的有效表示將

{ 
    "count" : 23, 
    "shows": [ 
     { 
        "title" : "TQA Weekly", 
        "description" : "Technology show", 
        "host" : "Steve Smith", 
        "logo" : "http://images.tqaweekly.com/tqa-weekly-logo.png", 
        "feed" : "http://feeds.podtrac.com/tTKj5t05olM$" 
     }, 
     { 
        "title" : "TWiT", 
        "description" : "This Week In Tech", 
        "host" : "Sarah Lane, etc", 
        "logo" : "http://logo/url", 
        "feed" : "http://feed/url" 
     } 
    ] 
}