Solved

Invalid JSON code.

Posted on 2011-02-10
6
492 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now