这是我得到的代码:
var tmp_kana_type = "hiragana";
var tmp_kana_set = "monographs";
cookie_symbols = {"symbols": []};
for (kana_row=0; kana_row<10; kana_row++) {
for (kana_column=0; kana_column<5; kana_column++) {
var tmp_JSON = {
"kana_type": tmp_kana_type,
"kana_set": tmp_kana_set,
"kana_row": kana_row,
"kana_column": kana_column,
"selected": 0,
"correct": 0,
"total": 0
};
cookie_symbols.symbols.push(tmp_JSON);
}
}
console.log(cookie_symbols); // works
var to_string = JSON.stringify(cookie_symbols);
console.log(to_string); // works
var to_json = JSON.parse(to_string);
console.log(to_json); // works
$.cookie("test_cookie1", "test string");
console.log($.cookie("test_cookie1")); // works
$.cookie("test_cookie2", JSON.stringify(cookie_symbols)); // does not work (why?)
console.log($.cookie("test_cookie2")); // does not work (null)
console.log(JSON.parse($.cookie("test_cookie2"))); // does not work (null)
JSON.stringfy()不能使用$ .cookie(),而我认为应该这样做。我做错了什么,我该如何解决或做这项工作?我发现了this answer,这也是我所做的,但在我的情况下,由于某些原因它不起作用。我正在使用this jQuery cookie plugin。