Posted By

chrisaiv on 07/11/11


Tagged

json as3


Versions (?)

AS3: JSON.decode


 / Published in: ActionScript 3
 

I always have trouble preparing JSON to work nicely with as3corelib. Here's an example of what I do whenever the array I'm looking for is nested within more JSON. This really isn't for anyone other than myself.

  1. function jsonHandler( e:Event ):void
  2. {
  3. var rawJSON:String= URLLoader(e.currentTarget).data;
  4. var bookStart:String = "[{";
  5. var bookEnd:String = "}]";
  6. rawJSON = rawJSON.slice(
  7. rawJSON.indexOf( bookStart ),
  8. rawJSON.lastIndexOf( bookEnd ) + bookEnd.length );
  9. //trace( rawJSON );
  10. var array:Array = JSON.decode(rawJSON) as Array;
  11. trace( array.length );
  12. }

Report this snippet  

You need to login to post a comment.