借助LocalStorage在HTML5中进行数组检索

时间:2014-10-17 08:39:35

标签: arrays html5 local-storage

我的本​​地存储文件中有1个条目  10/10/2014 19:23:34(日期和时间)作为密钥和

{"entries":[{"name":"s","contact":"s","location":"s","email":"sweety@yahoo.com","detail":"s","f_name":"form1"}]} 

(表单字段记录)作为值

所以我的问题是如何使用Name = sContact = s等分隔参数来获取此数组...

1 个答案:

答案 0 :(得分:0)

如果您还没有解析数据,可以这样解析:

var json = localStorage.getItem('10/10/2014 19:23:34');

if (json) {
    var data = JSON.parse(json);

    if (data !== null) {
        // then you can try to do something with the data within it
        var entries = data.entries;

        for (var i = 0, l = entries.length; i < l; i++) {
            var entry = entries[i];
            console.log(entry.name, entry.contact, entry.location, entry.email);
        }
    }
}