Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 ]

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Can you please post the output of the JSON as is.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 584 Times in 565 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •