By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,570 Members | 1,613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,570 IT Pros & Developers. It's quick & easy.

JSON array, can't access result ?!?!

P: n/a
see the following example. When I simplified the test case, I seem to
be getting an error I cant explain, though the read succeeds and I go
on to iterate on the JSON result. Using Firebug or other mens, one can
verify that the object was populated, and that the array is present.
But I can't seem to get the expression to access it right. OR there is
some kind of exception that is being silently thrown that I am not
reading.
Happy to put in another try/catch, or other additions, if I can just
tell where...

tia -Brian

<http://www.screenlight.com/maplab/xTest.html>

--

Nov 27 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

go********@screenlight.com wrote:
see the following example. When I simplified the test case, I seem to
be getting an error I cant explain, though the read succeeds and I go
on to iterate on the JSON result. Using Firebug or other mens, one can
verify that the object was populated, and that the array is present.
But I can't seem to get the expression to access it right. OR there is
some kind of exception that is being silently thrown that I am not
reading.
Happy to put in another try/catch, or other additions, if I can just
tell where...

tia -Brian

<http://www.screenlight.com/maplab/xTest.html>

--
Hm. I'm seeing that this doesn't work with "for (var i in obj)" , but
does seem to work with "for (var i=0; i<obj.length; i++)" which is the
correct technique for looping through an array anyway.

I get the following output:

DEBUG: error in read
DEBUG: [object Object]

the first seems to be from "for (var i in obj)", the second from "for
(var i=0; i<obj.length; i++)". Same in Firefox and IE6.

Moral of the story: don't use "for (var i in obj)" to loop through an
array, only for looping through object properties.

David

Nov 27 '06 #2

P: n/a
see the following example. When I simplified the test case, I seem to
be getting an error I cant explain.......

<http://www.screenlight.com/maplab/xTest.html>

Hm. I'm seeing that this doesn't work with "for (var i in obj)" , but
does seem to work with "for (var i=0; i<obj.length; i++)" which is the
correct technique for looping through an array anyway.

I get the following output:

DEBUG: error in read
DEBUG: [object Object]

the first seems to be from "for (var i in obj)", the second from "for
(var i=0; i<obj.length; i++)". Same in Firefox and IE6.
1) thanks for the reply 2) Huh?
my script output shows a single iteration for the array, just as if
it say an object, not an array there...
I commented out the non-array tries for a moment. Are you sure of what
you are seeing? There should be 41 elements iterated through...

Nov 27 '06 #3

P: n/a

googleA...@screenlight.com wrote:
see the following example. When I simplified the test case, I seem to
be getting an error I cant explain.......
>
<http://www.screenlight.com/maplab/xTest.html>
Hm. I'm seeing that this doesn't work with "for (var i in obj)" , but
does seem to work with "for (var i=0; i<obj.length; i++)" which is the
correct technique for looping through an array anyway.

I get the following output:

DEBUG: error in read
DEBUG: [object Object]

the first seems to be from "for (var i in obj)", the second from "for
(var i=0; i<obj.length; i++)". Same in Firefox and IE6.

1) thanks for the reply 2) Huh?
my script output shows a single iteration for the array, just as if
it say an object, not an array there...
I commented out the non-array tries for a moment. Are you sure of what
you are seeing? There should be 41 elements iterated through...
Ok, look at your code very closely here:

for (var i=0; i < gContainer.dSubs_J.fsDataA.length; i++) {
console.info( i);
gContainer.makeSubObjMarker( gContainer.dSubs_J.fsData[i]);
}

See the last line? You're indexing a nonexistent property (due to a
typographical error) and it's throwing an error which breaks you out of
your loop. That's why you're only seeing one. Using firebug I get
gContainer.dSubs_J.fsDataA.length == 41.

Nov 27 '06 #4

P: n/a
David Golightly wrote:
googleA...@screenlight.com wrote:
see the following example. When I simplified the test case, I seem to
be getting an error I cant explain.......

<http://www.screenlight.com/maplab/xTest.html>
>
Hm. I'm seeing that this doesn't work with "for (var i in obj)" , but
does seem to work with "for (var i=0; i<obj.length; i++)" which is the
correct technique for looping through an array anyway.
>
I get the following output:
>
DEBUG: error in read
DEBUG: [object Object]
>
the first seems to be from "for (var i in obj)", the second from "for
(var i=0; i<obj.length; i++)". Same in Firefox and IE6.
>
1) thanks for the reply 2) Huh?
my script output shows a single iteration for the array, just as if
it say an object, not an array there...
I commented out the non-array tries for a moment. Are you sure of what
you are seeing? There should be 41 elements iterated through...

Ok, look at your code very closely here:

for (var i=0; i < gContainer.dSubs_J.fsDataA.length; i++) {
console.info( i);
gContainer.makeSubObjMarker( gContainer.dSubs_J.fsData[i]);
}

See the last line? You're indexing a nonexistent property (due to a
typographical error) and it's throwing an error which breaks you out of
your loop. That's why you're only seeing one. Using firebug I get
gContainer.dSubs_J.fsDataA.length == 41.
A typo! that's it, a missing capital A at the end of the variable
name...
thanks very much. I guess I am still getting used to the Javascript
kind of errors, you know, where I can call things that dont exist and
in some cases that is not an error, and creates no msg.

btw- the external, global scope completion routine was written because
I couldn't get some syntax right.. If there was a way to copy the
'data' param in the ioBind completion to a gContainer property
directly, I would be all eyes and ears

Nov 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.