ilteris kaplan blog

Archive of blog posts since 2005

April 5, 2008

Wiki

Using JSON with as3

#wiki

In order to use JSON support in as3, you have to download as3corelib. After this, it’s pretty straightforward in Flex Builder.

package {
	import com.adobe.serialization.json.JSON;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class JSONExample extends Sprite
	{
		private var theFileContent:String;
		
		private var theObj:Object;
		public function JSONExample()
		{
			var url:String = "some url";
			var loader:URLLoader = new URLLoader();
			var request:URLRequest = new URLRequest(url);
			loader.load(request);
			loader.addEventListener(Event.COMPLETE, completeHandler);
			
		}
		
		private function completeHandler(e:Event):void {
		trace(e.target.data);
		var theObj:Object = JSON.decode(e.target.data);
		//trace(theObj.totalResultsAvailable);
		
		for ( var i in theObj ) {
 			trace( i );	
			}	
		trace(theObj.ResultSet.totalResultsAvailable);
		
		
		
		}
	}
}

sources

*Mike Chamber’s Blog *JSON and AS3 URLRequest Class *Using JSON with Yahoo! Web Services FIXME (add the notation content here.) *JSON - JavaScript Object Notation

Continue Reading

Back to Archive