搜尋

首頁  >  問答  >  主體

javascript - localstorage存对象数组的方法

如题,想保存的数据是一个很复杂的对象数组
该用什么方法实现,
我先把数组的每个值也就是一个对象转化成了字符串,塞进了一个新数组,想把这个数组编译出来,eval结果失败了,有什么好的思路和方法
{"message":"column value (QUAD) 0.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column value (QUAD) 0.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueKeyed start. Key count: 2.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column name: cpu_id.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column value (QUAD) 0.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query on table cpu_info_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column name: slot_id.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column name: slot_id.","@version":"1","@timestamp":"2016-08-24T12:44:19.176Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table interface_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column name: slot_id.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column name: hidden.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column value (QUAD) 0.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueKeyed start. Key count: 1.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column name: hidden.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"column value (QUAD) 0.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueKeyed start. Key count: 2.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query on table cpu_info_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.175Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table host_info_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query on table system_cpu_info_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE MISS during query, prev=gtm_global_stat, curr=system_cpu_info_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table interface_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueKeyed start. Key count: 1.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during rollup, prev=host_info_stat, curr=host_info_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during query, prev=system_cpu_info_stat, curr=system_cpu_info_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during rollup, prev=host_info_stat, curr=host_info_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.174Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table profile_serverssl_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.173Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during rollup, prev=tmm_stat, curr=tmm_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.173Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.173Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during rollup, prev=profile_serverssl_stat, curr=profile_serverssl_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.173Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueKeyed start. Key count: 1.","@version":"1","@timestamp":"2016-08-24T12:44:19.173Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table host_info_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.173Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table profile_clientssl_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during rollup, prev=profile_clientssl_stat, curr=profile_clientssl_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during rollup, prev=profile_clientssl_stat, curr=profile_clientssl_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table profile_serverssl_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE MISS during rollup, prev=profile_clientssl_stat, curr=profile_serverssl_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table profile_clientssl_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.167Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table profile_tcp_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE HIT during rollup, prev=profile_tcp_stat, curr=profile_tcp_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE MISS during rollup, prev=profile_rewrite_stat, curr=profile_tcp_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"tmstat_query_rollup on table profile_tcp_stat called.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"CACHE MISS during rollup, prev=profile_tcp_stat, curr=profile_clientssl_stat.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"},{"message":"getTMValueUNKeyed start.","@version":"1","@timestamp":"2016-08-24T12:44:19.166Z","type":"syslog","host":"192.168.10.90","tags":["_grokparsefailure_sysloginput"],"priority":0,"severity":0,"facility":0,"facility_label":"kernel","severity_label":"Emergency"}

怪我咯怪我咯2780 天前753

全部回覆(2)我來回復

  • 天蓬老师

    天蓬老师2017-04-11 13:08:20

    JSON.parse


    比如:

    //有一个数组对象
    [
        {a: 1},
        {b: 2}
    ]
    //通过JSON.stringify讲数组转为字符串存到localStorage
    //然后再用JSON.parse将localStorage里的取得的字符串进行格式化

    回覆
    0
  • 迷茫

    迷茫2017-04-11 13:08:20

    存的时候

    localStorage[你的key] = JSON.stringify(数组);

    取的时候

    data = JSON.parse(localStorage[你的key]);

    回覆
    0
  • 取消回覆