Skip to content Skip to sidebar Skip to footer

Read Json File Data Using Javascript?

function uploadJsonFunction(){ var jsonURL = 'C:\Users\My Documents\new\WebContent\JsonFiles\TreeJson\countries.json'; } countries.json is valid json and the above path has cou

Solution 1:

$.ajax({
    url: "\countries.json",
    success: function (data) {
        var obj = JSON.parse(data);
    }
});

For safety reasons, The C:\Users\My Documents\new\WebContent\JsonFiles\TreeJson\countries.json url won't work in a browser.

Solution 2:

Please try to see this example.

Jquery to get Json

-or-

How to use a JSON file in javascript

Hope may help you.

Solution 3:

Why not to try Google: http://www.json.org/js.html

I used this for Android app that worked with PhoneGap(HTML+Javascript+JQuery)

Worked fine.

My Method:

var link_name = pathtojson.json

$.getJSON(link_name,
function(data){
var ttext = (data["SearchResponse"]["Translation"]["Results"][0]["TranslatedTerm"]);
document.getElementById('ttexti').innerHTML = ttext;
}
);

Post a Comment for "Read Json File Data Using Javascript?"