javascript - JSON loop a multidimensional array to with node.js -


having read on different methods please bear me try explain.

i trying retreive data twitch api , loop user.name results array possibly inside object. using nodejs has javascript.

so far when run following nice json response.

var request = require('request');      request({url: 'https://api.twitch.tv/kraken/channels/twitch/follows?limit=3'}, function(err, res, json) {         if (err) {             throw err;         }          console.log(json);      }); 

this logs same if 1 visit https://api.twitch.tv/kraken/channels/twitch/follows?limit=3

or better visualized

json structure

now want select follows -> user -> name object. more so, loop every user -> name in response.

i thought need convert string object tried

    var obj = json.parse(json); 

but returns first {3} objects in tree. went ahead , tried

var request = require('request');      request({url: 'https://api.twitch.tv/kraken/channels/twitch/follows?limit=3'}, function(err, res, json) {         if (err) {             throw err;         }          (var i=0; i<json.length; i++) {          var obj = json.parse(json.follows[i].user.name);         console.log(obj);          }      }); 

and returns

typeerror: cannot read property '0' of undefined 

for testing purposes got rid of loop , have 1 return 1 bit of info. having tried multiple instances of rearranging call either error or "undefined" back.

nothing seems work, going right way?

as json object here, should use for-in though there no length property. here json.follows array. should use loop.

var len = json.follows.length; (var i=0; i< len; i++) {     console.log(json.follows[i].user.name); } 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -