SoftwareNerd
SoftwareNerd

Reputation: 1895

Json parse error when parsing an object in jquery?

Hi all i have an JSON Object which i am trying to parse it in jquery but when i try to parse it i get an erro saying

        JSON.parse: bad control character in string literal

here is my json object

         {
         "StoreId": 20314,
         "DisplayDateFomratId": null,
         "EnableSearchSuggest": null,
         "DefaultProductSort": null,
         "CompanyTollfreeNumber": null,
         "FavIcon": null,
         "StoreLogo": null,
         "UseExpressCheckout": null,
         "UsersMustLoginToseePricing": null,
         "CallForPricing": null,
         "StoreName": "RA",
         "CompanyName": null,
         "SSLDomainName": "localhost: 4445",
         "DomainName": "localhost: 4445",
         "StoreAddressId": 20840,
         "TomeZoneId": 10152,
         "DateFormatId": 10152,
         "CartQuantityBoxesId": 10192,
         "ProductDisplayModeId": 10187,
         "SearchTypeId": 10193,
         "DownForMaintenance": false,
         "ShowThumbnailsInCart": null,
         "ShowProductPrice": true,
         "EnableWishlist": true,
         "ShowEstimatedShippingInCart": null,
         "ShowEstimatedTaxInCart": true,
         "AllowReturns": false,
         "AlternativeProductDisplay": true,
         "HideAddToCartWhenNoStock": false,
         "LoginToRequestQuote": null,
         "AddTocartToSeePricing": false,
         "ShowProductWarranty": false,
         "EnableNewProducts": true,
         "EnableFeaturedProducts": true,
         "EnableTopSellers": true,
         "AllowGiftWrapping": false,
         "DoNotAllowBackOrders": false,
         "DownTimeMessage": "",
         "StoreProductDesc": null,
         "SEOScript": null,
         "MetaTitle": "Radians\u001fInc.",
         "MetaDescription": "Radians\u001fInc.",
         "MetaKeywords": "Radians\u001fInc."
        }

when i am trying to acces this Model object via

         var settings = JSON.parse('@Html.Raw(Json.Encode(@Model))');

and in the above statement my "@Model" has the object and how do i escape those ' with "\".

Upvotes: 2

Views: 471

Answers (1)

Satpal
Satpal

Reputation: 133403

You don't need to use JSON.parse and also quotes. Just use.

var settings = @Html.Raw(Json.Encode(Model))

Json.Encode Method converts a data object to a string that is in the JavaScript Object Notation (JSON) format.

Upvotes: 3

Related Questions