Want to import JSON data into my local storage -


i trying store json data local storage. not able find way do. please assist me if has idea it.this json data.http://67.209.121.4/products.json. highly appreciated.thanks in advance!

as far know localstorage stores key/value pairs. therefore first stringify json , store it. read need string , parse back. see code:

var jn = {        "test": {            "test": 1,            "testx": 2,            "xtest": {                "x": 1,                "y": 2            },            "test2": 1        },        "xx":{            "x":2,            "y": 3,            "z": [1,2,3]        }    };      localstorage.setitem("mydata", json.stringify(jn));    var data = json.parse(localstorage.getitem("mydata"));    console.log(data);

you need run code inside of html-file run, because of sandboxing.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -