简体   繁体   中英

Calling local class

I'm trying to call a static method from a class called "JSON", however the import I'm doing already has this method. How can I call a local class?

I've tried this:

mypackage.subpackage.JSON.encode(param1)

In C # the above would work, but I do not know why in ActionScript below does not work.

import flash.utils.ByteArray;

public class Package extends ByteArray
{
    public function writeJsonObject(param1:Object) : void
    {
        this.writeUTF(JSON.encode(param1));
    }
}

I get this error:

Error: 1061: Call to a possibly undefined method decode through a reference with static type Class

Try using JSON.stringify()

import flash.utils.ByteArray;

public class MyClass extends ByteArray
{
    public function writeJsonObject(param1:Object) : void
    {
        this.writeUTF(JSON.stringify(param1));
    }
}

Reference: https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/JSON.html

Also worth noting the difference between writeUTF and writeUTFBytes to understand exactly what's getting written to your ByteArray

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM