AS3: JSON.decode


/ Published in: ActionScript 3
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments


You need to login to view comments.