大家好我有一个JSON对象,我试图在jquery中解析它,但当我尝试解析它时,我得到一个错误的说法
JSON.parse: bad control character in string literal
这是我的json对象
{
"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."
}
当我尝试通过
访问此Model对象时 var settings = JSON.parse('@Html.Raw(Json.Encode(@Model))');
在上面的语句中我的“@Model”有对象,我如何逃避那些'with“\”。
答案 0 :(得分:3)
您不需要使用JSON.parse
和引号。只是用。
var settings = @Html.Raw(Json.Encode(Model))
Json.Encode方法将数据对象转换为JavaScript Object Notation(JSON)格式的字符串。