Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2009, 05:28 AM   PM User | #1
sanpops
New to the CF scene

 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sanpops is an unknown quantity at this point
Problem with the result list of json rpc call

We are facing a strange issue with json. After we assign the result to a variable - res, then try to print the values...
for(var j in res["list"]) {
alert(res['list'][j]['name']);// some of the values are coming as "undefined"
}
output:
ranjith
sandeep
nikhil
undefined
undefined
undefined

What could be the reason for this?

Thanks and regards,
sandeep@uhuroo.com
www.uhuroo.com [ Uhuroo is a web application that provides a smart and secure way of collaborating on documents with distributed teams ]
sanpops is offline   Reply With Quote
Old 07-29-2009, 07:44 AM   PM User | #2
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
Can you please post the output of the JSON as is.
ckeyrouz is offline   Reply With Quote
Old 07-29-2009, 08:32 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by sanpops View Post
alert(res['list'][j]['name']);// some of the values are coming as "undefined"

What could be the reason for this?
that those res['list'][j] branches don't contain a name property?

it might be faster/simpler to cache your object before iteration:


Code:
var ob=res["list"];
for(var it in ob) {
  alert(ob[it].name||"no name for "+it);
}
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Tags
json

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:42 AM.


Advertisement
Log in to turn off these ads.