as3 将 json 中的字符串评估为对象
我有一个 json 对象,我不知道编译时的一些值,但我知道所有对象在运行时都有效。因此,在下面的示例中,第一个跟踪将输出“50”,我希望第二个跟踪输出“100”,即 someObject.someparam 的值,该值在运行时定义。这可能吗?谢谢
var plan:Object = { "testParam": 50, "testParam2": "someObject.someParam" }
var someObject:Object = {"someParam": 100}// this actually doesn't get defined until runtime
trace ("testParam " + plan.testParam);
trace ("testParam2 " + someSortOfInterpreter(plan.testParam2);
I have a json object where I don't know some of the values at compile time, but I do know that all objects will be valid at runtime. So in the example below, the first trace will output "50" and I want the second trace to output "100", the value of someObject.someparam, which gets defined at runtime. Is this possible? Thanks
var plan:Object = { "testParam": 50, "testParam2": "someObject.someParam" }
var someObject:Object = {"someParam": 100}// this actually doesn't get defined until runtime
trace ("testParam " + plan.testParam);
trace ("testParam2 " + someSortOfInterpreter(plan.testParam2);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于我为什么使用“JSON 对象”,这没有多大意义。 JSON 是基于文本的表示法,稍后可以由您正在使用的特定编码语言进行解释。
因此,假设您的 JSON 字符串实际上是:
您可以在编译时完全省略“testParam”属性,然后解析该字符串并在运行时设置该属性。
首先:
then:
假设您使用 as3coreLib JSON 类来解码 json 字符串。
This doesn't make much sense to me as to why you are using a "JSON Object." JSON is text based notation that can later be interpreted by the specific coding language you are using.
So, assuming your JSON string is actually:
You could just leave out the "testParam" property entirely, at compile time, then parse the string and set that property at runtime.
Start with:
then:
This is assuming you're using the as3coreLib JSON class to decode the json string.
对象是动态的,您不必在运行时创建它。
您还可以检查它是否已设置
您可以随时设置它
,现在,设置后,它将正确跟踪
这是您遇到的麻烦吗?如果没有,也许您可以向我们提供有关您的问题的更多信息。
Objects are dynamic, it doesn't have to exist for you to create it at runtime.
You can also check to see if it has been set
You can set it whenever you want
and now, after it has been set, it will trace correctly
Is this what you are having troubles with? If not, maybe you could give us more info about your problem.