3

这是我得到的代码:

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() 而我认为它应该。我做错了什么,我该如何解决或使这项工作正常进行?我找到了这个答案,这几乎就是我所做的,但就我而言,由于某种原因它不起作用。我正在使用这个 jQuery cookie 插件

4

1 回答 1

4

我相信你的主要问题是你已经超过了最大 cookie 文件大小

于 2012-08-12T00:15:17.500 回答