Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Traversing multiple json results #6

Open
GoogleCodeExporter opened this issue Apr 22, 2015 · 1 comment
Open

Traversing multiple json results #6

GoogleCodeExporter opened this issue Apr 22, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Hi there

Love the toolkit, thanks a million for making it available. I'm using the 
Blackberry version in a Widget I'm creating and have a query regarding parsing 
multiple results:

Say for example we have a json string being returned as:

{ {"id":"1","title":"row 1"} , {"id":"2","title":"row 2"} }

When I run it through jsonParse I try to access each position of results as if 
it were an array (as I saw mentioned on another issue of a similar nature):

var events = jsonParse(result);
alert(events[0].id);

and to see how many results have been returned:

alert(events.length);

but each of these returns "undefined".

I realise I'm probably doing something really dumb or missing an obvious 
solution but at the moment I'm stumped. Note that in my specific case, using 
the "for(var x in y)" approach will not fit in to my code.

Any thoughts?

Cheers

Lee

Original issue reported on code.google.com by lsibbald...@gmail.com on 3 Jul 2010 at 1:52

@GoogleCodeExporter
Copy link
Author

Hi

I've since figured out that it was the structure of the json that was causing 
me problems.
Changing the above json sample to:

[ {"id":"1","title":"row 1"} , {"id":"2","title":"row 2"} ]

(note square enclosing brackets rather than curlies) successfully creates an 
object which can be checked by using

events.length

and I can also then use

events[0].id

to access the object properties.

Apologies for raising this as an issue.

Original comment by lsibbald...@gmail.com on 4 Jul 2010 at 10:52

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant