What is the best way (including frameworks) of working with JSON files? Using Javascript [closed]

-1

Folks, I have to list some data based on a json and also use some control structures with properties of that file, so what is the best way to work with them? if possible explain how to move from a .json file (without writing all of it in the code) to a javascript object.

    
asked by anonymous 17.07.2016 / 01:55

1 answer

1

Pure JS

For modern browsers, just use JSON.parse

var json = '{"result":true,"count":1}',
    obj = JSON.parse(json);

alert(obj.count);

See supported browsers:

  

link


jQuery

For jQuery:

$.getJSON( "caminho_do_arquivo/arquivo.json", function( data ) {
    // use 'data' aqui
});


Fallback solution

You can use external libraries like this, for example:

  

link

    
17.07.2016 / 02:17