Flex4将对象转换成json串
使用json需要先引入as3corelib.swc
1、将对象转换成json串
var obj:Object = new Object(); obj.filename = "1.jpg"; obj.filetype = "image"; obj.fileext = "jpg"; var str = JSON.encode(obj); Alert.show(str,"标题");
2、将数组转换成json串
var arr:Array = new Array(); var obj:Object = new Object(); obj.filename = "1.jpg"; obj.filetype = "image"; obj.fileext = "jpg"; arr.push(obj); obj = new Object(); obj.filename = "1.jpg"; obj.filetype = "image"; obj.fileext = "jpg"; arr.push(obj); var str = JSON.encode(arr); Alert.show(str,"标题");