我有一个json字符串/ javascript列表,我想在jcookies中保存
json字符串/ javascript列表看起来像
[ { "depot": { "id": "D1", "intersection": { "first": "Markham", "second": "Lawrence" }, "address": { "number": "25", "street": "Cougar Court", "city": "Scarborough", "province": "ON", "postal_code": "M1J3C5" } }, "vehicle": [ { "id": "V1", "depot_id": "D1", "model": "Ford Focus", "price": "45", "km_per_litre": "15", "cargo_cu_m": "120", "category": "Compact car", "image": "https://www.avis.com/car-rental/images/global/en/rentersguide/vehicle_guide/hyundaiaccent-ca-08.gif" } ] }
]
请告诉我如何将其存储在cookie中并从cookie中检索(转换为javascript变量)
答案 0 :(得分:0)
好吧,如果您确实已经将值作为字符串提供,那么您应该能够使用jquery cookie插件https://github.com/carhartl/jquery-cookie来保存值,如下所示:
$.cookie('jsonList', jsonString);
并像这样检索它:
jsonString = $.cookie('jsonList');