JSON encoding in as3
I have this code which Im using to pass data in JSON encoded format to php. Is there a way i can check at the php end if it was received and beamed in proper format?
var people:Array = new Array(); var person:Object = new Object(); var url:String = "http://localhost/ping.php"; var request:URLRequest = new URLRequest(url); var requestVars:URLVariables = new URLVariables(); var loader:URLLoader = new URLLoader(); person.fullname = "jon jay junior"; person.username = "jjj"; person.role = "ADMIN"; people.push(person); request.method = URLRequestMethod.POST; requestVars.myObject = JSON.encode(people); request.data = requestVars; loader.load(request);
As others have mentioned, you should look at the request with Firebug, LiveHTTPHeaders, or a similar tool (there are several for Firefox). This will let you see the format of the data.
If $_REQUEST['myObject'] is indeed null in PHP, then something is wrong. You should really attach a loader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError); to check for problems and/or run with the debug Flash player so you can see any exceptions going on.
If you are running this in a browser, a debug trick is to call Firebug's console.log via an ExternalInterface.call()