本文介绍了AS3 和 JSON:错误 1061的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我花了几个小时解决一个与 FLASH 中的 JSON 编码相关的可能很愚蠢的问题.

I spent hours around a possibly stupid problem relative to JSON encoding in FLASH.

我尝试做一些非常简单的事情:我创建了一个对象,并希望它在 JSON 中被序列化.

I Try to do something very simple : I make an object and I want it to be serialized in JSON.

但 Flash 告诉我

But Flash tells me

> 1061: Call to a possibly undefined method encode through a reference with static type Class.

这是我的代码.这是教程的副本这里.它有问题(我猜不是在教程中,在我的代码中),但我无法弄清楚可能是什么:

Here is my code. It's a copy of the tutorial here. Something is wrong in it (not in the tutorial I guess, in my code) but I can't figure out what is can be :

import com.adobe.serialization.json.JSON;

var member1:Object = new Object();
member1.firstName = "John"
member1.lastName = "Parker"
member1.age = "32"
member1.country = "Canada"
member1.job = "Programmer"

var member2:Object = new Object();
member2.firstName = "Peter"
member2.lastName = "Anderson"
member2.age = "30"
member2.country = "USA"
member2.job = "System administrator"

var myData:Object = {staff:[member1, member2]};

var myJson:String = JSON.encode(myData);

trace(myJson);

在行 var myJson:String = JSON.encode(myData);flash 产生上面提到的错误.让我确切地说,类 JSON 很好,它必须在 (my_project/com/adobe/serialization/json/JSON.as) 并且我可以在其中找到编码静态方法.

At the line var myJson:String = JSON.encode(myData); flash generate the error mentioned above.Let me precise that the class JSON is well where it has to be (my_project/com/adobe/serialization/json/JSON.as ) and that I can find the encode static method in it.

有人能告诉我我的错误在哪里吗?谢谢.

Can someone tell me where my mistake(s) is or are ?Thank you.

推荐答案

JSON.parseJSON.stringfy 是您在 Flash Player 11+ 中寻找的方法.

JSON.parse and JSON.stringfy are the methods you are looking for in Flash Player 11+.

JSON.encodeJSON.decode 是 Adob​​e AS3 库的一部分,但由于 Flash Player 具有本机 JSON 解析器,现在您不需要该类.

JSON.encode and JSON.decode were part of the Adobe AS3 lib but since the Flash Player has a native JSON parser now you don't need that class.

这篇关于AS3 和 JSON:错误 1061的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:40