Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Invalid JSON code.

Posted on 2011-02-10
6
Medium Priority
?
497 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:Gurvinder Pal Singh
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 2000 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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:Gurvinder Pal Singh
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

670 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