日期:2014-05-16  浏览次数:20330 次

Type 1120: Access of undefined property JSON 无法明确解析多名称引用 JSON
在AS3中用as3corelib的JSON来解析字符串错误如下:
引用
Type 1120: Access of undefined property JSON
无法明确解析多名称引用 JSON


as3corelib官方解释是:
引用

https://github.com/mikechambers/as3corelib/issues/171
If you’re using as3corelib like I’ve been using for quite some time now, you will notice this error. To fix it you simply need to remove the following import (it may vary based on your project structure):
import com.adobe.serialization.json.JSON;
and then you’ll need to modify your code to replace:

JSON.decode(myString);
and
JSON.encode(myObject);

to:

JSON.parse(myString);
and
JSON.stringify(myObject);

You can find the full details of the new implementation of the native JSON support in AS3 on Adobe’s Reference Site

注:就是说,解决办法就是不要用as3corelibe的实现:移除那个 import ,然后把对应的函数名改掉.因为flash player 11已经有了JSON类的实现。

如果编译时指定目标为Player 10及以下,则上述错误不会出现。如果按照上述方法修改,反倒出现错误:
引用
JSON in Flex. “Access of undefined property JSON”

此时,要么编译目标调整为Player 11,要么使用as2corelib类库