今天用flashplayer11编译以前用asolib中的json类来解析json数据的时候,发现编译报错。原来如此!!!
其中JSON包含两个静态方法 parse 和 stringify ,下面这个例子演示使用JSON

//AS文件 JSONLoader.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class JSONLoader extends Sprite
{
private var loader:URLLoader;

public function JSONLoader()
{
loader = new URLLoader(
new URLRequest("test.json"));
loader.addEventListener(Event.COMPLETE, onLoaded);
}

protected function onLoaded(event:Event):void
{
var items:Object = JSON.parse(loader.data);
for each(var item:Object in items)
{
try {
if(item.id != null) {
trace(item.id);
}
}
catch(e:Error) {
}
}
}
}
}

JSON文件 test.json
{
"image": "INGAME_BIRDS_PIGS.png",
"spriteCount": 4,
"sprite_0": { "id": "BIRD_BLACK_1" },
"sprite_1": { "id": "BIRD_BLACK_2" },
"sprite_2": { "id": "BIRD_BLACK_BLINK"},
"sprite_3": { "id": "BIRD_BLACK_F"}
}