Solved

Invalid JSON code.

Posted on 2011-02-10
6
493 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window.Open() is showing a blank page 9 31
jQuery delay animation 3 29
Where is java script information saved? 2 52
Adding Row and Cell on a table 14 19
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

772 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