Flex HTTPService json

import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.controls.Alert;
import com.adobe.serialization.json.JSON;

private var httpService:HTTPService = new HTTPService();
protected function button1_clickHandler(event:MouseEvent):void
{

httpService.url="http://localhost:8080/trf/xt/traffic";
httpService.method="POST";                         //重要,默认GET
httpService.contentType="application/json";    //重要,默认XML
httpService.showBusyCursor = true;
httpService.addEventListener(ResultEvent.RESULT,getResult);
httpService.addEventListener(FaultEvent.FAULT,getFailure);

var sub:Object= new Object();
sub.id=1;
var para:Object =new Object();
para.cmd="findXhjById";
para.token="token";
para.params= sub;
var jstr:Object=com.adobe.serialization.json.JSON.encode(para); //重要
httpService.send(jstr);

}

private function getResult(event:ResultEvent){

Alert.show("-----------success----------");
var obj:Object= com.adobe.serialization.json.JSON.decode(event.message.body.toString());
Alert.show("address:" + obj.detail.address);

}

private function getFailure(event:FaultEvent){
     Alert.show("-----------Failure----------");
}

上一篇:js便签笔记(10) - 分享:json2.js源码解读笔记


下一篇:IDS IPS WAF之安全剖析