FLEX4中 獲取JSON數據的一個例子

  公司要求使用JSON格式來獲取服務器端的數據
  通過谷歌大神幫助 成功解決了問題
  無奈服務器端返回的JSON格式兩邊都有括號
  費勁了幾番周折 才搞定 不敢獨享 發出來大家一起玩玩
  import com.adobe.lib.JSON;
  這個包是在官網上下的源代碼 然後封包 包名稱是自己起的
  1. 首先使用HTTPService 對象獲取數據
  2. 然後使用JSON來解析獲取的數據
  3. 最後使用ArrayCollection 綁定到DataGrid上
  發現數據有亂碼 在Application 中加入屬性 initialize="flash.system.System.useCodePage=true"
  數據格式如下 帶有括號 在程序中進行了簡單的過濾 ({"id":"1","totalCount":"1","results": [{"timeEarlyWarning":"","linkTel":"138900900","dis patchSources":"group","no":"電路- 21111111- 009","statusStr":"","appUserInfo":"","checkTime":" ","serviceModeDetail":"0132" ,"drafPerson":"黃xx","appManager":"","specialtyCheckerId":"","alter Man":"","actualFeedBackTime" :"","toDeps":"省分公司","dispatchGroupId":"","appBusinessDep":"","circui tNum":"","signTime":"","di spatchZOBId":"","signOpinion":"","appTime":"","dea lStatus":"new","clientEmail" :"","createTime":"2011-03-01 11:49","serviceModeDetailStr":"國內DDN電路","locationId":"2","circuitAppType":"client"}]}) 程序代碼如下 flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="flash.system.System.useCodePage=true" creationComplete="application1_creationCompleteHan dler(event)" > 0) { var results_array:Array = jsonObj.results as Array; arrColl = new ArrayCollection(results_array); } } protected function http_service_faultHandler(event:FaultEvent):void { trace("訪問服務器失敗"); } ]]--> width="761" height="159">
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章