JSON的动作脚本:如何获得一个JSON对象的属性和值? [英] JSON in Action Script: how to get the properties and values on a JSON object?

查看:289
本文介绍了JSON的动作脚本:如何获得一个JSON对象的属性和值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本来我有这个JSON和假设的属性可能会改变......

supposed i have this JSON, and supposed the properties may change...

'{"srcLocation":"pc","filename":"name","fileext":"jpg","url":""}';

首先,我想对他们所有属性(srcLocation,文件名等) 并使用性能我有我想要得到相应的价值。

first I want to get all the properties on them (srcLocation, filename etc) and using the properties I got I want to get the corresponding value..

如何能做到这一点在行动脚本?

how can I do that in action script?

推荐答案

首先,你需要去$ C C的JSON $的,可能使用的的as3corelib

First of all you need to decode the JSON, probably using as3corelib:

var jsonString:String = '{"srcLocation":"pc","filename":"name","fileext":"jpg","url":""}';
var decodedObj:Object = JSON.decode(jsonString);

然后,所有你需要做的是通过对象循环,让所有的名称/值对:

Then all you have to do is loop through the object to get all the name/value pairs:

for(var key:String in decodedObj) {
    trace("Name: " + key + " - Value: " + decodedObj[key];
}

将输出:

Name: srcLocation - Value: pc
Name: filename - Value: name
Name: fileext - Value: jpg
Name: url - Value:

这篇关于JSON的动作脚本:如何获得一个JSON对象的属性和值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆