6
Problem Accessing JSON Data on This Example
source link: https://www.codesd.com/item/problem-accessing-json-data-on-this-example.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Problem Accessing JSON Data on This Example
advertisements
this is a json i have, is valid, but for some reason if I access this query.pages.length
is "undefined"... how do i know the numebr of children of pages
then? are they children?
{
"query-continue":{
"allpages":{
"gapfrom":"Tron (film)"
}
},
"query":{
"pages":{
"174059":{
"pageid":174059,
"ns":0,
"title":"Tron"
},
"29799461":{
"pageid":29799461,
"ns":0,
"title":"Tron: Betrayal"
},
"2424602":{
"pageid":2424602,
"ns":0,
"title":"Tron: Deadly Discs"
},
"25415189":{
"pageid":25415189,
"ns":0,
"title":"Tron: Evolution"
},
"29958517":{
"pageid":29958517,
"ns":0,
"title":"Tron: Evolution - Battle Grids"
},
"22547607":{
"pageid":22547607,
"ns":0,
"title":"Tron: Legacy"
},
"29541046":{
"pageid":29541046,
"ns":0,
"title":"Tron: Legacy (soundtrack)"
},
"11825742":{
"pageid":11825742,
"ns":0,
"title":"Tron: Solar Sailer"
},
"8005401":{
"pageid":8005401,
"ns":0,
"title":"Tron: The Ghost in the Machine"
},
"29487895":{
"pageid":29487895,
"ns":0,
"title":"Tron: Uprising"
}
}
}
}
I wrote this code to count length of pages
:
count = 0;
for (var key in netData.query.pages) {
count = count + 1;
}
alert(count);
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK