如何从字符串创建动态对象?
这是我当前的代码,结果不正确:
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.
我希望前面的代码输出以下内容:
trace(o1); // result = [object Object]
trace(o1.x); // result = 200
trace(o1.y); // result = 400
提前致谢!
最佳答案
as3corelib包含一个JSON解析器,可以为您完成此操作。确保您研究了issues list,因为该库没有新发行版,并且其中存在很多错误,这些错误大多数在问题列表中得到解决。
关于flash - 如何在ActionScript 3.0(AS3)中以字符串形式创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1510554/