【发布时间】:2012-03-13 00:24:12
【问题描述】:
我正在解释一些来自输入的数据,该输入具有 ;其中特别是“M-F 8am - 8pm; Sat-Sum 9am-10pm”,它切断了我的 JSON 并使我的对象中断。我有什么方法可以解决这个问题??
{"id":null,"initPath":"/home","storeLocator":{"queryString":"edina"},"order":{"Store_ID":"10305","Store_Info":"7700 NORMANDALE BLVD, EDINA, MN, 55439","Hours_Of_Operation":"M-F 8am - 8pm; Sat-Sum 9am-10pm","Store_Phone":"111-222-3333","Language_ID":"4"},"orderLabel":{"Order_Summary":"Order Summary","Location":"Pick Up Location:","Hours":"Store Hours:","OC_Participation_Level_Description":"Participation Level:","OC_Type_Name":"Cake Type:","OC_Cake_Design_ID":"Design:","Shape":"Shape:","Size":"Size:","Serves":"Serves:","Price":"Price:","Tax":"Tax:","Total":"Total:","Top_Border_Icing_Color_ID":"Top Border:","Bottom_Border_Icing_Color_ID":"Bottom Border:","Decoration_Comment":"Decoration Comment:","Special_Request_Comment":"Special Request:","Personalization":"Message:","Personalization_Color_ID":"Message Color:","Upload_Image_Filename":"Upload Image:","Quantity":"Quantity:","OC_Salutation_ID":"Message:","Special_Occasion_Comment":"Comments:","Customer_First_Name":"First Name:","Customer_Last_Name":"Last Name:","Pickup_Date":"Pick Up Date:","Phone_No":"Phone Number:","Email_Address":"Email Address:","IP_Address":"IP Address:","Ordering_Device":"Ordering Device:","Ordering_OS":"Ordering OS:","Ordering_Browser":"Ordering Browser:","Store_id":"Store:","Language_id":"Language:","OC_Shape_Size_ID":"Shape Size","Back_Button":"Back","Place_Order_Button":"Place Order","Pickup_Time":"Pick Up Time:","Lead_Time":"Lead Time:","Days":"days","Image":"Image:"},"choices":{},"countryId":"US","languageId":"4"}
然后我将它存储在一个 cookie 中,然后在取回它时将它解析回来
{"id":null,"initPath":"/home","storeLocator":{"queryString":"edina"},"order":{"Store_ID":"10305","Store_Info":"7700 NORMANDALE BLVD, EDINA, MN, 55439","Hours_Of_Operation":"M-F 8am - 8pm
我正在使用此命令将 JSON 保存在 cookie 中
session = $.JSON.encode(session);
document.cookie = "dqcakes_session=" + encodeURIComponent(session) + "; path=/";
用这个解码
var session = getCookie("dqcakes_session");
session = $.JSON.decode(decodeURIComponent(session));
这可能是 encodeURIComponent 吗?
我只是对 JSON 使用了一个简单的解析器,它不可能是这样的。
【问题讨论】:
-
您可以在此处包含 JSON 吗?
-
我们需要一些代码来帮助您?
-
只是为了向未来的读者澄清:答案现在已包含在问题中。这两段 javascript 应该放在答案中,而不是问题中。
标签: jquery json cookies session-cookies