Solved

Invalid JSON code.

Posted on 2011-02-10
6
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…
Suggested Courses

630 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