简体   繁体   中英

GET request Flex / Actionscript 3

Struggling to find any documentation to do a simple GET request to a URL to return JSON in Actionscript / Flex.

Anyone know

Use the URLLoader API.

var myJSON :Object; //listing as per "key:" with "value"
var str_JSON: String = ""; //if you need text String not data Object

var siteloader :URLLoader = new URLLoader( new URLRequest( your_URL ) );

siteloader.addEventListener(Event.COMPLETE, whenSiteLoaded);

function whenSiteLoaded( evt :Event ) :void 
{
  myJSON = JSON.parse(evt.target.data); //get into Object
  str_JSON = evt.target.data; //get into String
  //... any other code
}

You should add to the above the listeners for error conditions (eg: a "file not found" situation)

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