JSON(JavaScript Object Notation)£¬ÊÇÒ»ÖÖÇáÁ¿¼¶µÄÊý¾Ý½»»»¸ñʽ£¬Ò×ÓÚ½âÎöºÍÉú³É£¬Ò²Ò×ÓÚÔĶÁºÍ±àд¡£ajaxµÄģʽºÍ¹¹¼Ü±»´óÁ¿ÍøÕ¾Ó¦Óã¬JSON×÷ΪÊý¾Ý´«Êä»áÊǸöÊ×Ñ¡¡£ËäÈ»AS3¶ÔXMLµÄ½âÎöÒѾºÜºÃÁË
¡¡¡¡JSON(JavaScript Object Notation)£¬ÊÇÒ»ÖÖÇáÁ¿¼¶µÄÊý¾Ý½»»»¸ñʽ£¬Ò×ÓÚ½âÎöºÍÉú³É£¬Ò²Ò×ÓÚÔĶÁºÍ±àд¡£ajaxµÄģʽºÍ¹¹¼Ü±»´óÁ¿ÍøÕ¾Ó¦Óã¬JSON×÷ΪÊý¾Ý´«Êä»áÊǸöÊ×Ñ¡¡£ËäÈ»AS3¶ÔXMLµÄ½âÎöÒѾºÜºÃÁË£¬µ«XML×÷ΪÊý¾Ý´«ÊäÊý¾ÝÁ¿´ó£¬·þÎñÆ÷¸ºµ£»á¹ýÖØ¡£JSON±¾ÉíµÄ½á¹¹¾Í¼òµ¥Ò×ÓÚÀí½â£¬ËüµÄÌصã¾ÍÊÇÊý¾ÝÁ¿Ð¡£¬Êý¾ÝµÄ½á¹¹ÇåÎú¡£
¡¡¡¡ÏÂÃæ˵ÏÂas3¶ÔJSONµÄ»ñÈ¡ºÍ·¢ËÍ(PS:http://code.google.com/p/as3corelib/ ¿ÉÒÔÏÂÔص½JSONµÄÀà¿â)£º
Json´úÂë:
- [{"type":"pic","num":"1"},
- {"type":"text","num":"2"},
- {"type":"swf","num":"3"},
- {"type":"html","num":"4"}]
ActionScript´úÂë:
- 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 getJSON extends Sprite {
- public function getJSON() {
-
- var urlLoader:URLLoader = new URLLoader();
-
- urlLoader.load(new URLRequest( “http://cuplayer.com/json.php” ));//ÕâÀïÊÇÄãÒª»ñÈ¡JSONµÄ·¾¶
- urlLoader.addEventListener(Event.COMPLETE, decodeJSONHandler);
- }
- private function decodeJSONHandler(event:Event):void {
- var jsonArray:Array = JSON.decode( URLLoader( event.target ).data );
- //»ñÈ¡Êý×éÖд洢µÄÊý¾Ý
- for (var i=0; i<jsonArray.length; i++) {
- trace( jsonArray[i].type );
- }
- }
- }
- }