PDA

View Full Version : Having trouble decoding a json array



BarryOg
7 Jul 2007, 2:43 PM
I'm passing the following string to the Ext.util.json.decode()



["","111","1112asdf","1112asdfgfg","1112asdfgfg324","21342","2134252","213425223342","213425223342b"

,"213425223342c","2222222222222","3333424","asdf","asdffdsa","asdfsafdasdffffffffffffff","attack","bang"

,"barry","barrytest","cats","catsrats","easdfsafdasdfffffffffffff","fear","fill it up","hello","it works"

,"it works alright","jack","japan","muppet","player1","sleepIsForWeak","sometimes slow","take your hat

off","test","whatdoyouknow","while(1){}","zzz"]


but its only returning a string not an array object. I've encoded this string on the other side using php 5.2's built in json encode method, and from my knowledge of json it appears to be formatted right, am I doing something wrong here?

evant
7 Jul 2007, 3:42 PM
I think it's because you don't have any object tags.
[] denotes an array, {} denotes an object, so technically all you have is an array of strings (I don't know if the decoder would fix it up for you).

Try



[{"","111","1112asdf","1112asdfgfg","1112asdfgfg324","21342","2134252","213425223342","213425223342b"

,"213425223342c","2222222222222","3333424","asdf","asdffdsa","asdfsafdasdffffffffffffff","attack","bang"

,"barry","barrytest","cats","catsrats","easdfsafdasdfffffffffffff","fear","fill it up","hello","it works"

,"it works alright","jack","japan","muppet","player1","sleepIsForWeak","sometimes slow","take your hat

off","test","whatdoyouknow","while(1){}","zzz"}]

BarryOg
8 Jul 2007, 4:08 AM
I realised what I was doing wrong, I was placing the response text into a div and than in another function I was decoding the contents of that div and trying access the array elements. Unfortunately the contents of the div weren't being updated fast enough so that's what was giving me an error. If I put another button in to perform accessing the array that it works fine. So my problem is trying to get the value of responseText back to the function that makes the Ajax.request.