A
A
Artem Pavliienko2018-05-16 15:13:35
JSON
Artem Pavliienko, 2018-05-16 15:13:35

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))
    });

Then I want to load it into a variable and take it from it and write it down.
var DATA = JSON.parse(localStorage.getItem('accounts'));

I tried to write it in different ways with an object, but it didn’t output the way I needed.
5afc1fd2d8814435551287.jpeg
json piece:
[{
  "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"]
    }
  }
}]

Please tell me how to write to a variable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-05-16
@kvazarmp

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 question

Ask a Question

731 491 924 answers to any question