javascript - How to get number of response of JSON? -


this question has answer here:

that json request

http://www.omdbapi.com/?s=harry

follow link see structure of response. how can number of objects in order create for loop?

first need json.parse data (string) in case:

var data = json.parse(string); 

getting number of items is:

data.length; 

you can same file (assuming node.js):

require('fs').readfile(json.parse(file), 'utf8', function (err, data {     if (err) throw err;     // data parsed }); 

then iterate using for-loop array you're interested in:

for (var prop in data) {     // item     var item = data[prop]; } 

iteration nowadays doesn't require a-priori knowledge of array length:

for (var = 0; < data.length; ++i) 

that json seems have search array of objects (see self: http://json.parser.online.fr/)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -