0
o = {
    "photos": {
        "page": 1,
        "pages": 46,
        "perpage": 5,
        "total": "230",
        "photo": [{
            "id": "6643924777",
            "owner": "34653895@N08",
            "secret": "3b7c2f6469",
            "server": "7153",
            "farm": 8,
            "title": "Huevos rellenos de bonito del norte Serrats",
            "ispublic": 1,
            "isfriend": 0,
            "isfamily": 0},
        {
            "id": "6371789575",
            "owner": "53643555@N08",
            "secret": "dda25093e0",
            "server": "6105",
            "farm": 7,
            "title": "ALBÓNDIGAS DE CARNE",
            "ispublic": 1,
            "isfriend": 0,
            "isfamily": 0},
        {
            "id": "6200723807",
            "owner": "17738873@N00",
            "secret": "bf4fc5c84f",
            "server": "6159",
            "farm": 7,
            "title": "albóndigas en salsa",
            "ispublic": 1,
            "isfriend": 0,
            "isfamily": 0},
        {
            "id": "6201239628",
            "owner": "17738873@N00",
            "secret": "def72cc124",
            "server": "6128",
            "farm": 7,
            "title": "albóndigas en salsa",
            "ispublic": 1,
            "isfriend": 0,
            "isfamily": 0},
        {
            "id": "6171324677",
            "owner": "34653895@N08",
            "secret": "9f7a7489f5",
            "server": "6161",
            "farm": 7,
            "title": "Pastel de patata con bonito del norte de Conservas Serrats y bechamel",
            "ispublic": 1,
            "isfriend": 0,
            "isfamily": 0}]}

}

This is the flickr API json result of a query I am tring like this

for (var key in o) {
    for (var key1 in o[key]) {
        var current = o[key][key1].id;
        console.log(key1);    //returns the pages information
        console.log(current); //returns null
    }    
}

Basically i need to construct images with this format

<img src="http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}.jpg" />

2 Answers 2

5
for (var i = 0; i < o.photos.photo.length; i++) {
    var photo = o.photos.photo[i];

    var img = document.createElement('img');
    var src = 'http://farm' + photo.farm + '.staticflickr.com/' + 
               photo.server + '/' + photo.id + '_' + photo.secret + '.jpg';
    img.setAttribute('src', src);

    // TODO: do something with the img DOM element we just created
}

and here's a live demo.

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

Comments

2

Try

jQuery.getJSON() - Load JSON-encoded data from the server using a GET HTTP request.

or

jQuery.parseJSON - Takes a well-formed JSON string and returns the resulting JavaScript object

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.