Solved

Invalid JSON code.

Posted on 2011-02-10
6
491 Views
Last Modified: 2013-11-08
Hello,

I need to access this code to write out a webpage.  I didn't write this code and I'm told it was either used or generated by dojo -- but I'm a novice, so I don't know.  I want to learn.  I want to use javascript and jQuery to access this code. I understand JS and JQ although just haven't really had a chance to use them consistently enough to master.  I keep getting this error when I try to validate it using jsonlint:

syntax error, unexpected TINVALID at line 1
Parsing failed

Here is the code

var data = {
    “categories”: [
        {
            "N": “nwItem1”,
            "O": “Composition”,
            "V": “School Supplies > Paper> Notebooks” 
        },
        {
            "N": “nwItem2,
            "O": “Crayons”,
            “V”: “Elementary > Art > Art Supplies” 
        },
        {
            “N”: “nwItem3”,
            “O”: “Calculators”,
            “V”: “High School > College Prep> Trigonometry” 
        },
        {
            “N”: “nwItem4”,
            “O”: “Maps”,
            “V”: “Middle School > US History > Civil War” 
        } 
    ],
    “brands”: [
        {
            “N”: “nwItem11”,
            “O”: “National” 
        },
        {
            “N”: “nwItem22,
            “O”: “Crayola” 
        },
        {
            “N”: “nwItem33”,
            “O”: “Texas Instruments” 
        },
        {
            “N”: “nwItem44”,
            “O”: “Atlas” 
        }; 
    ],
    “grades”: [
        {
            “U”: “http: //www.donson.net/cp/Notebooks-Academic-School/RED-43481.”,
            “O”: “Kindergarten” 
        },
        {
            “U”: “http: //www.crayola.com/”,
            “O”: “Fourth Grade” 
        },
        {
            “U”: “http: //www.ti.com/”,
            “O”: “Twelth Grade” 
        },
        {
            “U”: “http: //shop.nationalgeographic.com/ngs/product/books/atlases-and-reference/national-geographic-9th-edition-atlas-of-the-world---softcover?code=SR60001”,
            “O”: “Sixth Grade” 
        } 
    ],
    “purchase”: [
        {
            “U”: “http: //www.amazon.com”,
            “O”: “Kindergarten” 
        },
        {
            “U”: “http: //www.walmart.com/”,
            “O”: “Fourth Grade” 
        },
        {
            “U”: “http: //www.overstock.com/”,
            “O”: “Twelth Grade” 
        },
        {
            “U”: “http: //www.bn.com”,
            “O”: “Sixth Grade” 
        }; 
    ]
};

Open in new window


Your help is appreciated
0
Comment
Question by:K_dot
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34868011
why do the beginning double quote look different in line 2, in your code above? can you try correcting the same?
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34868024
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 34870136

There are some mismatched quotes but it's been tidied up here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26813916.html</title>
<script src="http://code.jquery.com/jquery-1.4.3.min.js" language="javascript"></script>
<script language="JavaScript">

var data = {
    "categories": [
        {
            "N": "nwItem1",
            "O": "Composition",
            "V": "School Supplies > Paper> Notebooks" 
        },
        {
            "N": "nwItem2",
            "O": "Crayons",
            "V": "Elementary > Art > Art Supplies" 
        },
        {
            "N": "nwItem3",
            "O": "Calculators",
            "V": "High School > College Prep> Trigonometry" 
        },
        {
            "N": "nwItem4",
            "O": "Maps",
            "V": "Middle School > US History > Civil War" 
        } 
    ],
    "brands": [
        {
            "N": "nwItem11",
            "O": "National" 
        },
        {
            "N": "nwItem22",
            "O": "Crayola" 
        },
        {
            "N": "nwItem33",
            "O": "Texas Instruments" 
        },
        {
            "N": "nwItem44",
            "O": "Atlas" 
        } 
    ],
    "grades": [
        {
            "U": "http: //www.donson.net/cp/Notebooks-Academic-School/RED-43481.",
            "O": "Kindergarten" 
        },
        {
            "U": "http: //www.crayola.com/",
            "O": "Fourth Grade" 
        },
        {
            "U": "http: //www.ti.com/",
            "O": "Twelth Grade" 
        },
        {
            "U": "http: //shop.nationalgeographic.com/ngs/product/books/atlases-and-reference/national-geographic-9th-edition-atlas-of-the-world---softcover?code=SR60001",
            "O": "Sixth Grade" 
        } 
    ],
    "purchase": [
        {
            "U": "http: //www.amazon.com",
            "O": "Kindergarten" 
        },
        {
            "U": "http: //www.walmart.com/",
            "O": "Fourth Grade" 
        },
        {
            "U": "http: //www.overstock.com/",
            "O": "Twelth Grade" 
        },
        {
            "U": "http: //www.bn.com",
            "O": "Sixth Grade" 
        }
    ]
};

$(function() {

  for ( var item in data ) {
    $("#root").append( $("<li/>").text( item ) );
    $("#root").append( children( data[item] ) );
  }

});

function children( node ) {
  var result = $("<ul/>");
  for ( var item in node ) {
    $(result).append( $("<li/>").text( item ) );
    $(result).append( subordinates( node[item] ) );
  }
  return result;
}

function subordinates( node ) {
  var result = $("<ul/>");
  for ( var item in node ) {
    $(result).append( $("<li/>").text( item + ": " + node[item] ) );
  }
  return result;
}

</script>
</head>
<body>

<ul id="root">
</ul>

</body>
</html>

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:K_dot
ID: 34871782
gurvinder, thanks.  I actually saw the blog at coderanch before I came here to ask the question.  The issue is sorta different than what I'm doing and I really couldn't follow what exactly the two people were talking about concerning "bytes" and whatnot.
0
 

Author Closing Comment

by:K_dot
ID: 34871796
Thanks, Proculopsis!
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34871933
why you didn't answer the question i asked in my first reply ? wasn't i asking a question related to the question?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now