Reputation: 345
I need to get and send request from/to server. i found a code in this site but it not working for me. api url is true and i can get data "{"out":355}" from firefox.
import com.adobe.serialization.json.JSON;
var request:URLRequest=new URLRequest();
request.url="******************************************"
request.requestHeaders=[new URLRequestHeader("Content-Type", "application/json")];
request.method=URLRequestMethod.GET;
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE, receive);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, notAllowed);
loader.addEventListener(IOErrorEvent.IO_ERROR, notFound);
loader.load(request);
function receive(event:Event):void
{
var myResults=JSON.decode(event.target.data);
trace(myResults);
}
ERROR:
Scene 1, Layer 'MAIN PAGE', Frame 1, Line 15, Column 25 1061: Call to a possibly undefined method decode through a reference with static type Class.
Upvotes: 0
Views: 187
Reputation: 505
import com.adobe.serialization.json.JSON;
var request:URLRequest=new URLRequest();
request.url="******************************************"
request.requestHeaders=[new URLRequestHeader("Content-Type", "application/json")];
request.method=URLRequestMethod.GET;
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE, receive);
loader.load(request);
function receive(event:Event):void
{
trace(event.target.data);
var json: Object = JSON.parse(event.target.data);
trace("json.out = ", json.out);
}
Result:
{"out":352}
json.out = 352
Upvotes: 1