自定义对象未完全编码为 JSON 对象
我有以下课程:
public class PartBean extends DatabaseObjectBean{
[Bindable]
public var partNumber:String;
[Bindable]
public var description:String;
public var enterpriseIdentifiers:ArrayList;
}
零件已经这样定义。 零件编号 = -1 描述 = 测试 该列表填充了另一个对象[“Name1”,“Name2,“Name3”]等。
在我调用的另一个对象中:
import com.adobe.serialization.json.JSONEncoder;
public function blah(){
JSONEncoder encoder = new JSONEncoder();
Alert.show(encoder.encode(part);
}
我最终得到这个字符串:{“description”:“Test”,“partNumber”:“- 1"}
我不确定为什么数组没有被编码。
I have the following class:
public class PartBean extends DatabaseObjectBean{
[Bindable]
public var partNumber:String;
[Bindable]
public var description:String;
public var enterpriseIdentifiers:ArrayList;
}
Part is already defined as such.
Part Number = -1
Description = Test
The list is filled with another Object["Name1", "Name2, "Name3"] etc..
In another object I call:
import com.adobe.serialization.json.JSONEncoder;
public function blah(){
JSONEncoder encoder = new JSONEncoder();
Alert.show(encoder.encode(part);
}
I end up with this string: {"description":"Test","partNumber":"-1"}
I am not sure why the array is not being encoded as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须为 ArrayList 编写自己的序列化代码。 ActionScript 提供的 JSON 编码器仅对本机 ActionScript 对象进行编码。
You'll have to write your own serialization code for the ArrayList. The JSON encoder provided with ActionScript will only encode native ActionScript objects.
答案似乎很简单,编码器需要可绑定项目才能看到它们。
It seems the answer is simply that the encoder needs the items to be bindable in order to see them.