> Which didn’t work (same issue as before) so it seems it's a little more than 
> just plain objects that have this issue?

No. Same problem. The problem is with the setting of the properties. When you 
then get the properties, the properties are renamed and undefined.

> This on the other hand does work and is probably a nice way to encapsulate 
> the issue as you can use dot notation and get type safety outside the class.

Yes. It works (and I’ve used this pattern, but kind of annoying if you ask me.

The best way to handle it is probably to define interfaces with getters and 
setter of the properties. Something like this will likely work, but I have 
never taken the time to test:

package 
        public interface JsonResponse
        {
                function get shortdesc():String;
                function get homepage():String;
                function set shortdesc(value:String):void;
                function set homepage(value:String):void;
        }
}
           var info:JsonResponse = JSON.parse(service.data);
           var status:int = service.status;

           if (status == 200) {
               description = info.shortdesc;
               homepage = info.homepage;
           }
           service.removeEventListener(Event.COMPLETE, projectInfo);
           service = null;
       }

I would be interested in knowing if it does work.

Harbs 

> On Nov 27, 2017, at 10:05 AM, Justin Mclean <jus...@classsoftware.com> wrote:
> 
> Hi,
> 
>> It’s a limitation with the Google compiler. Any untyped objects can be 
>> renamed.
> 
> Which with JSON is just about always going to be.
> 
> I wonder if we can use dynamic classes to get around this?
> 
> I just tried:
> package {
> public dynamic class ReturnedJSON {
>    public function ReturnedJSON(obj:Object) {
>        for (var field:String in obj) {
>           this[field] = obj[field];
>        }
>    }
> }
> }
> 
> var info:ReturnedJSON = new ReturnedJSON(JSON.parse(service.data));
> 
> Which didn’t work (same issue as before) so it seems it's a little more than 
> just plain objects that have this issue?
> 
> 
> This on the other hand does work and is probably a nice way to encapsulate 
> the issue as you can use dot notation and get type safety outside the class.
> 
> package {
> public class ReturnedJSON {
> 
>    public var description:String;
>    public var homepage:String;
> 
>    public function ReturnedJSON(obj:Object) {
>        for (var field:String in obj) {
>            description = obj["description"];
>            homepage = obj["sitename"];
>        }
>    }
> }
> }
> 
> Thanks,
> Justin

Reply via email to