help pls on json..

S

shotokan99

i have this code:
//-----------------------------------//
var custrec={
"customer":[
{
"id" : 123,
"name": "joy"
},
{
"id" : 555,
"name": "ritchie"
},
{
"id" : 666,
"name": "xander"
}
]
}
for(i=0; i<= 2; i++ ){
cust= custrec.customer.name;
id=custrec.customer.id;
document.write(id+' '+cust+'<br/>');
}

//-------------------------------//

on the for..loop i specified that it will loop until 2. is there a way
for me to automatically determine the number of records (am i using
the right term?) of custrec.cusomter . like a typrical
array....myarray.length.

tnx.
 
M

Martin Honnen

shotokan99 said:
on the for..loop i specified that it will loop until 2. is there a way
for me to automatically determine the number of records (am i using
the right term?) of custrec.cusomter . like a typrical
array....myarray.length.

Sure, custrec.customer is an Array object so it has a property
custrec.customer.length that you can use, just as with other arrays.
 
S

shotokan99

actually i tried it

for(i=0; i <= custrec.customer.length; i++){
..
..
..
}

and its not working...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top