3
I am trying to solve a question with a plugin that uses jQuery but do not know how to insert a JSON file in Jsfiddle.
This JSON is a string and comes from a file .json
.
3
I am trying to solve a question with a plugin that uses jQuery but do not know how to insert a JSON file in Jsfiddle.
This JSON is a string and comes from a file .json
.
3
Depends a little on where you get JSON.
If it is a string you can paste directly into the Javascript space:
var str = '{"objeto": {"foo":"bar"}}';
var json = JSON.parse(str);
if it’s a larger file I usually put it in an ajax script:
function buscaJSON(url, cb) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var data = JSON.parse(request.responseText);
cb(null, data);
} else {
cb('Error: ' + request.responseText);
}
};
request.onerror = function() {
cb('Unknown error');
};
request.send();
}
buscaJSON('https://rawgit.com/SergioCrisostomo/version-files/master/json_example.json', function(err, json) {
alert(JSON.stringify(json, null, 4));
});
Browser other questions tagged json jsfiddle
You are not signed in. Login or sign up in order to post.
I did it! I created it on Github and then generated a Raw, just like in your example.
– StillBuggin
@Eduardoalmeida good! is very useful, I was glad when I discovered this possibility too.
– Sergio
Well, now I can prepare my real problem! It seems that moderators don’t like it when we say "thank you," so, Danke Schön
– StillBuggin