Skip to main content

Bug Tracker

Side navigation

#11551 closed bug (invalid)

Opened April 03, 2012 04:31PM UTC

Closed April 03, 2012 06:03PM UTC

uncaught exception: Invalid JSON

Reported by: sheir@magma.ca Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:
Description

Hello,

I am new to jQuery and am working on an application that uses .NET4 (C#) + MVC3 + Razor view engine + jQuery + JSON.

Using Firefox v11 with the Firebug javascript debugger add-in.

In my viewpage .cshtml I have the following:

@using System.Linq;

@using System.Web.Script.Serialization;

@using Models;

@using Infrastructure;

@model Models.JobSettingsModel

@{

JobSettingsModel defModel = ViewBag.DefaultModel;

JavaScriptSerializer serializer = new JavaScriptSerializer();

string json = serializer.Serialize(defModel);

}

<script type="text/javascript">

var obj = '@Html.Raw(json)';

var oModel1 = jQuery.parseJSON(obj);

function foo() {

if (oModel1 != null) {

alert("OModel1 is not null");

}

else {

alert("oModel1 is null!");

}

if (obj != null) {

alert("obj is not null");

}

else {

alert("obj is null");

}

}

foo();

</script>

When I view my page in Firefox, Firebug's Script tab shows the javascript as:

<script type="text/javascript">

var obj =

'{"IncludeWatermark":false,"WatermarkText":"empty","IncludePageNumbering":false,"OverwriteOutputFileIfExists":

true,"OutputFilename":"dummyDefault.pdf","OutputLibraryLocation":"c:\\\\temporary","User":{"Name":"Sheir","DisplayName":"Sheir","GivenName":"Sheir","MiddleName":null,"Surname":"","SamAccountName":"sheir","IsActive":true,

"UserId":"mydomainINC\\\\sheir"},

"SharePointLocationUrl":null,"FeedbackUrl":null,"AppDescriptionUrl":null}';

var oModel1 = jQuery.parseJSON(obj);

Firebug's Console tab + Error tab shows:

uncaught exception: Invalid JSON:

{"IncludeWatermark":false,"WatermarkText":"empty","IncludePageNumbering":false,"OverwriteOutputFileIfExists":t

rue,"OutputFilename":"dummyDefault.pdf","OutputLibraryLocation":"c:\\temporary","User":{"Name":"Sheir",

"DisplayName":"Sheir","GivenName":"Sheir","MiddleName":null,"Surname":"","SamAccountName":"sheir","IsActive":true,"UserId

":"mydomainINC\\sheira"},"SharePointLocationUrl":null,"FeedbackUrl":null,"AppDescriptionUrl":null}

Line 0

**************************

First I copied the oModel1 parseJSON param (everything from the { to the } ) and stuck it in the

http://jsonlint.com/

and clicked their Validate button which says

{

"IncludeWatermark": false,

"WatermarkText": "empty",

"IncludePageNumbering": false,

"OverwriteOutputFileIfExists": true,

"OutputFilename": "dummyDefault.pdf",

"OutputLibraryLocation": "c:\\\\temporary",

"User": {

"Name": "Sheir",

"DisplayName": "Sheir",

"GivenName": "Sheir",

"MiddleName": null,

"Surname": "",

"SamAccountName": "sheir",

"IsActive": true,

"UserId": "mydomainINC\\\\sheira"

},

"SharePointLocationUrl": null,

"FeedbackUrl": null,

"AppDescriptionUrl": null

}

> Valid JSON

Then I copied the uncaught exception message and did same and got ...

{

"IncludeWatermark": false,

"WatermarkText": "empty",

"IncludePageNumbering": false,

"OverwriteOutputFileIfExists": true,

"OutputFilename": "dummyDefault.pdf",

"OutputLibraryLocation": "c:\\temporary",

"User": {

"Name": "Sheir",

"DisplayName": "Sheir",

"GivenName": "Sheir",

"MiddleName": null,

"Surname": "",

"SamAccountName": "sheir",

"IsActive": true,

"UserId": "mydomainINC\\sheira"

},

"SharePointLocationUrl": null,

"FeedbackUrl": null,

"AppDescriptionUrl": null

}

Parse error on line 16:

..., "UserId": "mydomainINC\\sheira"

----------------------^

Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

So I am perplex to say the least.

Attachments (0)
Change History (1)

Changed April 03, 2012 06:03PM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

This is the bug tracker for jQuery bugs. It looks like your JSON is not valid since backslashes should be escaped, but again this is not the place to ask for help. Try http://forum.jquery.com or StackOverflow.