1

Alright guys, I'm fairly new to Json, so sorry if this doesn't make alot of sense..

I'm trying to retrieve data from a json file to display in a html document using jQuery. I've been able to console.log the raw json data with this code:

$(document).ready(function ($) {
    $.getJSON("http://mtgjson.com/json/AllSets.json",    function (data) {
        console.log(data);
    });
});

Wich gives me the following data.

enter image description here

I'm trying to make an <ul> and put all the data 'name' into the <li> using jQuery. So I end up with a huge list of names. I've been searching for the past 3 hours and haven't found anything that can help me. So any help would be appreciated greatly. Thanks in advance.

2
  • 1
    I'd recommend reading w3schools.com/json/json_syntax.asp to further understand how to access JSON properties Commented Mar 5, 2014 at 13:48
  • Thank you, I will definitly get into that. Commented Mar 5, 2014 at 13:51

2 Answers 2

4

Something like this

jQuery(document).ready(function($) {
    $.getJSON("http://mtgjson.com/json/AllSets.json",    function (data) {

        var ul = $('<ul />');

        $.each(data, function(key, value) {
            ul.append(  $('<li />', {text: value.name})  );
        });

        $('body').append(ul);
    });
});

FIDDLE

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that's what I was looking for. I'll dig into the 'each', 'key' and 'value' attributes and see if I can get some more info on this subject. Thank you for the help!
0

A point to start could be this:

$.getJSON("http://mtgjson.com/json/AllSets.json",    function (data) {
   $.each(data, function(key, value){
    console.log(key, value);
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.