如何在actionscript 3.0(as3)中创建一个字符串形式的对象

10 flash actionscript actionscript-3

如何从字符串创建动态对象?

这是我当前的代码,结果不正确:

var s1:String = '{x:200, y:400}';
var o1:Object = Object(s1);

trace(o1); // result = {x:200, y:400}
trace(o1.x) // result = ReferenceError: Error #1069: Property x not found on String and there is no default value.
trace(o1.y) // result = ReferenceError: Error #1069: Property x not found on String and there is no default value.
Run Code Online (Sandbox Code Playgroud)

我想以前的代码输出以下内容:

trace(o1); // result = [object Object]
trace(o1.x); // result = 200
trace(o1.y); // result = 400
Run Code Online (Sandbox Code Playgroud)

提前致谢!

spe*_*der 4

as3corelib包含一个 JSON 解析器,可以为您完成此操作。请务必研究问题列表,因为该库还没有新版本,并且其中存在大量错误,这些错误大部分已在问题列表中解决。