Getjson To Fetch Data From This Json Array
This is a sample json array from my code. How can i use getJSON to fetch data from this array. 'Restoration': [ { 'Easy': { 'value':
Solution 1:
using jQuery jQuery.getJSON():
$.getJSON('ajax/test.json', function(data) {
console.log(data); //see your data ( works in Chrome / FF with firebug)console.log(data["Restoration"][0]["easy"]["value"]) //should output 1
});
Solution 2:
This is an alternative to use "jQuery.getJSON()" because sometimes we don't have a "domain/file.json" or somewhere to do the $get or we don't want to use jQuery for this simple process.
This method parses json from string.
You can do it with simple javascript like this:
//json string for testingvar jsonstr = '{"id":"743222825", "name":"Oscar Jara"}';
//parse jsonvardata = JSON.parse(jsonstr);
//print in console
console.log("My name is: " + data.name + " and my id is: " + data.id);
Hope this helps.
Regards.
Post a Comment for "Getjson To Fetch Data From This Json Array"