Bug Tracker

Opened 7 years ago

Closed 7 years ago

#11551 closed bug (invalid)

uncaught exception: Invalid JSON

Reported by: sheir@… 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 = '@…(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.

Change History (1)

comment:1 Changed 7 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.