Bug Tracker

Modify

Ticket #11551 (closed bug: invalid)

Opened 14 months ago

Last modified 14 months ago

uncaught exception: Invalid JSON

Reported by: sheir@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.5.2
Keywords: Cc:
Blocking: Blocked by:

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

comment:1 Changed 14 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.