2

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 "\".

3
  • if @Html.Raw(Json.Encode(@Model)) is returning the json you mentioned previously, it should work. What is instead being returned? Commented Jan 24, 2014 at 18:16
  • i have a model in my object , i am not able to access it untill i parse it with JSON Commented Jan 24, 2014 at 18:21
  • @KevinB can you look at the jsfiddle [jsfiddle.net/XVB3Q/1/] Commented Jan 25, 2014 at 9:23

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.