/ 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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function jsonHandler( e:Event ):void { var rawJSON:String= URLLoader(e.currentTarget).data; var bookStart:String = "[{"; var bookEnd:String = "}]"; rawJSON = rawJSON.slice( rawJSON.indexOf( bookStart ), rawJSON.lastIndexOf( bookEnd ) + bookEnd.length ); //trace( rawJSON ); var array:Array = JSON.decode(rawJSON) as Array; trace( array.length ); }