Answer the question
In order to leave comments, you need to log in
How to work with JSON?
Hello.
I have a test json file with data, I need to write it to localStorage and then take it from there and perform manipulations.
Uploaded the file and saved to localStorage:
$.getJSON( '../json/dataAccount.json', function( data ) {
localStorage.setItem('accounts', JSON.stringify(data))
});
var DATA = JSON.parse(localStorage.getItem('accounts'));
[{
"Acmeindustries": {
"domain": ["com Commercial organization", "net Network", "org Organization"],
"ipaddress": ["12.12.162.0", "165.12.21.170"]
}
},
"Unitedindustrial": {
"domain": ["net Commercial ", "net Network", "org Organization"],
"ipaddress": ["12.12.162.0", "165.12.21.170"]
}
}
}]
Answer the question
In order to leave comments, you need to log in
not very clear, but how do you need
var a = [
{
"Acmeindustries": {
"domain": [
"com Commercial organization",
"net Network",
"org Organization"
],
"ipaddress": [
"12.12.162.0",
"165.12.21.170"
]
}
},
{
"Unitedindustrial": {
"domain": [
"net Commercial ",
"net Network",
"org Organization"
],
"ipaddress": [
"12.12.162.0",
"165.12.21.170"
]
}
}
]
console.log(a) // [{...}, {...}]
localStorage.setItem('dt', JSON.stringify(a))
var b = JSON.parse(localStorage.getItem('dt'))
console.log(b) // [{...}, {...}]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question