Domanda

Previously, I was using XML to store information about the podcasts that my app used to deal with. However, the the complexity of using the parser made me transition from XML to JSON and a few other reasons.

Here is what my XML looks like:

<?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 -->  

and here is what my JSON looks like:

{
    "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
    ]
}  

My question is: have I done the conversion from XML to JSON correctly? The aim is to represent the same information in JSON.

I am sure I made syntax mistakes along with others. Please do point them out. I am a newbie in JSON

È stato utile?

Soluzione

Well, that isn't valid JSON (as you can see when you try to parse it), so no.

For example:

  • The semicolon after "count" : 23 is wrong (it should be a comma),
  • There is a list after that where it shouldn't be (there should be an identifier before that)
  • That list contains elements like a dictionary would, so these are illegal
  • If that list were a dictionary, it would be illegal since it contains the same key twice.

A valid representation would be

{
    "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"
        }
    ]
}  
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top