AS3和JSON:错误1061错误、JSON

2023-09-08 12:38:48 作者:寒江雪

我花了几个小时一个可能是愚蠢的相对JSON编码的FLASH问题各地。

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告诉我,

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

下面是我的code。这是本教程这里的副本。什么是错在它(不是在教程中,我想,在我的code),但我想不出有什么可以是:

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:字符串= JSON.en code(myData的);闪光灯产生上面提到的错误。 让我precise该类JSON是很好的地方那一定是(MY_PROJECT / COM /土坯/串行/ JSON / JSON.as),而且我可以找到它的EN code静态方法。

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.

谁能告诉我在哪里,我的错误(s)是或有? 谢谢你。

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

推荐答案

JSON.parse JSON.stringfy 是您正在寻找在Flash Player 11 +的方法。

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

JSON.en code JSON.de code 是土坯AS3的一部分LIB但由于Flash播放器有一个本地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.

 
精彩推荐
图片推荐