Javascript - 将2d数组保存到本地存储并检索

时间:2013-01-08 16:30:58

标签: javascript jquery local-storage

我有一个二维数组,包含我需要保存到本地存储的信息,然后再检索。这是我的数据:

var content_array = [
    ["0","Mobile Application Development","CT5006","01/14/2013","Note"],
    ["1","Java Programming","CT5005","01/16/2013","Note"],
    ["2","Multimeida Application Development","CT5011","02/13/2013","Note"]
];

任何简单的方法将其转换为字符串然后再转换为2D数组?

1 个答案:

答案 0 :(得分:8)

使用原生JSON.stringify方法:

var str = JSON.stringify(content_array);

然后,您可以使用JSON.parse方法将其恢复为实际数组:

var content_array = JSON.parse(str);