Adobe AIR使用JSON

电脑技术 电脑技术 1275 人阅读 | 0 人回复 | 2022-04-10

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
https://github.com/airsdk/as3cor ... le/JSONExample.mxml
  1. <?xml version="1.0" encoding="utf-8"?>

  2. <!--
  3. Adobe Systems Incorporated(r) Source Code License Agreement
  4. Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
  5.        
  6. Please read this Source Code License Agreement carefully before using
  7. the source code.
  8.        
  9. Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
  10. no-charge, royalty-free, irrevocable copyright license, to reproduce,
  11. prepare derivative works of, publicly display, publicly perform, and
  12. distribute this source code and such derivative works in source or
  13. object code form without any attribution requirements.
  14.        
  15. The name "Adobe Systems Incorporated" must not be used to endorse or promote products
  16. derived from the source code without prior written permission.
  17.        
  18. You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
  19. against any loss, damage, claims or lawsuits, including attorney's
  20. fees that arise or result from your use or distribution of the source
  21. code.
  22.        
  23. THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
  24. ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
  25. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
  27. NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
  28. OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  31. OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  33. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
  34. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. -->

  36. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
  37.         layout="absolute"
  38.         creationComplete="service.send()" viewSourceURL="srcview/index.html">
  39.        
  40.         <mx:Script>
  41.                 <![CDATA[
  42.                         import mx.collections.ArrayCollection;
  43.                         import mx.rpc.events.ResultEvent;
  44.                         import com.adobe.serialization.json.JSON;
  45.                        
  46.                         private function onJSONLoad(event:ResultEvent):void
  47.                         {
  48.                                 var rawData:String = String(event.result);
  49.                                 var arr:Array = (JSON.decode(rawData) as Array);
  50.                                
  51.                                 var dp:ArrayCollection = new ArrayCollection(arr);
  52.                                
  53.                                 grid.dataProvider = dp;
  54.                         }
  55.                 ]]>
  56.         </mx:Script>
  57.        
  58.         <mx:HTTPService
  59.                 id="service"
  60.                 resultFormat="text"
  61.                 url="http://weblogs.macromedia.com/mesh/mashedpotato.json"
  62.                 result="onJSONLoad(event)" />
  63.        
  64.         <mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10">
  65.                 <mx:columns>
  66.                         <mx:DataGridColumn headerText="Service" dataField="src"/>
  67.                         <mx:DataGridColumn headerText="Title" dataField="title"/>
  68.                 </mx:columns>
  69.         </mx:DataGrid>
  70.        
  71. </mx:Application>
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门推荐