AS3 Json integration quick and dirty

Ive been dealing with Json data recently which may be a faster/less convoluted alternative for handling data between backend and frontend interfaces than xml. This is probably the quickest and lightweight serialization i’ve found that works.

Credit goes to http://www.ekameleon.net for the class file, and can be found here.

Implementation goes something like this:-

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import com.serialization.json.json;

var uvars:URLVariables = new URLVariables();
var ureq:URLRequest = new URLRequest();
ureq.url = “http://blah.com”;
ureq.method = URLRequestMethod.POST;
ureq.data = json.serialize(uvars);
ureq.contentType = “application / json”;

var uload:URLLoader = new URLLoader();
uload.addEventListener(Event.COMPLETE, jsonLoadComplete);
uload.load(ureq);

private function jsonLoadComplete(e:Event) {

var data= json.deserialize(e.currentTarget.data);

}

Leave a Reply

Spam protection by WP Captcha-Free

Posted