Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Re: reading jso...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 11 Topic 35473 of 37168
Post > Topic >>

Re: reading json object with jquery

by Jorge <jorge@[EMAIL PROTECTED] > May 7, 2008 at 01:25 AM

On May 6, 5:27 am, "Jon Paal [MSMD]" <Jon nospam Paal @[EMAIL PROTECTED]
 everywhere dot
com> wrote:
> A solution to the original json structure:
>
> success: function(json, status) {
>   var records = json.Records;
>   var str = "";
>   if(records ){
>    for(var i = 0; i < records.length; i++){
>     for(var j in records[i]){
>      str += j + " --> " + records[i][j] + "\n";
>     }
>    }
>   alert(str);
>   }

Jon, a couple of things about this :

1.- Note, just in case it matters, that the for(var j in records[i])
loop does not specify the order in which the properties of records[i]
are enumerated : you may end up with both firstname,lastname or
lastname,firstname and there is no way to tell in advance what the
order will be.

2.- It's usually a good idea to query the hasOwnProperty method in
order to screen out (unwanted) inherited properties :

for (var j in records[i]) {
 if ( records[i].hasOwnProperty(j) ) {
  str += j + " --> " + records[i][j] + "\n";
 }
}

--Jorge.
 




 11 Posts in Topic:
reading json object with jquery
"Jon Paal [MSMD]&quo  2008-05-04 11:50:48 
Re: reading json object with jquery
Jorge <jorge@[EMAIL PR  2008-05-04 17:13:41 
Re: reading json object with jquery
"Jon Paal [MSMD]&quo  2008-05-04 20:57:51 
Re: reading json object with jquery
Lasse Reichstein Nielsen   2008-05-05 07:01:33 
Re: reading json object with jquery
Jorge <jorge@[EMAIL PR  2008-05-05 03:04:48 
Re: reading json object with jquery
jdalton <John.David.Da  2008-05-05 06:07:09 
Re: reading json object with jquery
Jorge <jorge@[EMAIL PR  2008-05-05 14:12:20 
Re: reading json object with jquery
Thomas 'PointedEars' Lahn  2008-05-06 21:24:18 
Re: reading json object with jquery
"Jon Paal [MSMD]&quo  2008-05-05 20:27:16 
Re: reading json object with jquery
Jorge <jorge@[EMAIL PR  2008-05-06 00:16:57 
Re: reading json object with jquery
Jorge <jorge@[EMAIL PR  2008-05-07 01:25:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 11:17:17 CDT 2008.