jquery - Unable to access JSON content after reading from a file -


i've spent hours , hours searching reading json file using js. closest tut found https://gist.github.com/zuch/6224600.

cells.json:

{   "cells": [     {       "img": "img/singlestitch_thumb.jpg",       "url": "http://www.google.com",       "description": "an interactive 'kite' sketch based on favorite letter[requires java]",       "smallwin": true     },     {       "img": "img/text3d_thumb2.jpg",       "url": "http://www.yahoo.com",       "description": "animated custom font design in 3d (featured on 'processing' site)[requires java]",       "smallwin": true     },     {       "img": "img/jazzer_thumb.jpg",       "url": "http://flickr.com",       "description": "a 3d musician 'plays along' arbitrary audio tracks[req. javajsyn]",       "smallwin": true     }   ] } 

testjson.html:

var cells = [];  $.getjson( "cells.json", function( json ) {      $.each(json, function(i, lv_1) {          $.each(lv_1, function(j, lv_2) {              $.each(lv_2, function(k, lv_3) {                 //console.log( k + ':' + lv_3 + '' );                 //console.log( json.parse(k + ':' + lv_3 + '') );                 cells.push( k + ':' + lv_3 + '' );             });         });      }); });  console.log(cells); 

this error.

console.log( cells[0].url ); // typeerror: cells[0] undefined

i cannot access element within.

attached zip file package. can use firefox or setup local server test with. https://www.dropbox.com/s/nmfq98s7raep92r/json%20test.zip?dl=0

thank you!

seems making harder necessary. once have data, can use (though perhaps i'm missing something):

$.getjson("cells.json", function (json) {      var cells = json.cells;     console.log( cells[0].url );  }); 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -