PDA

View Full Version : Json parse error on <p>



jelly46
05-10-2013, 08:56 AM
Hello

I am unable to to edit a json file i need to add some updates but i keep getting


Error: Parse error on line 8:
... "text" : "

company name -----------------------^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'


I am trying to add a paragraph with a section and when i put a <p> i get the error

here is the code, please can you assist?



{
"subSections":
[
{
"title" : "The main website",
"url" : "main-website",
"linktitle" : "The main website",
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"
}, {
"title" : "The main reception",
"url" : "main-reception",
"linktitle" : "The main reception",
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"
}, {
"title" : "A heading",
"url" : "a url heading",
"linktitle" : "A heading",
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p>Our role involves ensuring that there is a warm friendly service for our patients and families when they come to GOSH.</p><p> Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p><p> It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"
}, {
"title" : "A heading",
"url" : "a url heading",
"linktitle" : "A heading",
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>"
}, {
"title" : "A heading",
"url" : "a url heading",
"linktitle" : "A heading",
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>"
}, {
"title" : "A heading",
"url" : "a url heading",
"linktitle" : "A heading",
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>"
}, {
"title" : "A heading",
"url" : "a url heading",
"linktitle" : "A heading",
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, </p>"
}
]
}

jscheuer1
05-10-2013, 09:19 AM
Seems to work OK like so:


<script type="text/javascript">
var j = JSON.parse('{\
"subSections":\
[\
{\
"title" : "The main website",\
"url" : "main-website",\
"linktitle" : "The main website",\
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"\
}, {\
"title" : "The main reception",\
"url" : "main-reception",\
"linktitle" : "The main reception",\
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"\
}, {\
"title" : "A heading",\
"url" : "a url heading",\
"linktitle" : "A heading",\
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p>Our role involves ensuring that there is a warm friendly service for our patients and families when they come to GOSH.</p><p> Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p><p> It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"\
}, {\
"title" : "A heading",\
"url" : "a url heading",\
"linktitle" : "A heading",\
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p>Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>"\
}, {\
"title" : "A heading",\
"url" : "a url heading",\
"linktitle" : "A heading",\
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>" \
}, {\
"title" : "A heading",\
"url" : "a url heading",\
"linktitle" : "A heading",\
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>"\
}, {\
"title" : "A heading",\
"url" : "a url heading",\
"linktitle" : "A heading",\
"text" : "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, </p>"\
}\
]\
}');
</script>

Or, using the unaltered code from your post as an external file (json.json in this example), this also works OK:


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
$.getJSON('json.json', function(data){
$('#output').html(data.subSections[0].text);
});
});
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>

jelly46
05-10-2013, 10:02 AM
Hello John

thanks for this, it does work.

The error arises when i i put an extra <p> in one of the sections.

I just need to update a few bits and it comes back with errors.

C

jscheuer1
05-10-2013, 10:17 AM
Show the actual contents of the json file that's giving you errors.

Oh, and it might not be an added p. I found I could p all I wanted in the file as long as it was still valid JSON. One big NoNo would be using double quote marks (") within an entry.