3 Replies Latest reply on Apr 29, 2011 7:36 AM by BigZ2011

    Need JSON example for mobile app

    BigZ2011 Level 1

      Hello, everyone.  I'm looking for a simple example of a mobile application built in Hero that can hit a JSON service and parse the output.  Thank you very much in advance!!

        • 1. Re: Need JSON example for mobile app
          BigZ2011 Level 1

          After some research, I'm kind of on my way but I'm still a bit lost.  I've added the following code:

           

          <fx:Declarations>

           

          <!-- Place non-visual elements (e.g., services, value objects) here -->

           

          <s:HTTPService id="DirectionGetter"

          resultFormat="

          text" url="http://geocoding.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/geocoding/find_structured/ house:80;+street:Linienstraße;+city:Berlin.js"

          result="ParseJSONDirections(event)"

          showBusyCursor="true">

           

          </s:HTTPService>

           

          </fx:Declarations>

           

          Then, in the <fx:Script> area I've added:

          private function ParseJSONDirections(event:ResultEvent):void
          {
          var rawData:String = String(event.result);
          lblTest.text = rawData;
          }

           

          But nothing happens.  Any advice, folks?

          • 2. Re: Need JSON example for mobile app
            Zolotoj Level 3

            Try the following code:

            <?xml version="1.0" encoding="utf-8"?>
            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()"
                           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
                <fx:Declarations>
                   
                   
                   
                    <!-- Place non-visual elements (e.g., services, value objects) here -->
                   
                   
                   
                    <s:HTTPService id="DirectionGetter"              
                       resultFormat="text"
                       url="http://geocoding.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/geocoding/find_structured/ house:80;+street:Linienstra%C3%9Fe;+city:Berlin.js"                            
                     result="ParseJSONDirections(event)"                        
                    showBusyCursor="true">                       
                    </s:HTTPService>
                   
                   
                   
                </fx:Declarations>
               
               
                <fx:Script>
                    <![CDATA[
                        import mx.rpc.events.ResultEvent;

             

                        private function ParseJSONDirections(event:ResultEvent):void
                        {
                            var rawData:String = String(event.result);
                            lblTest.text = rawData;
                        }
                        private function init():void
                        {
                            DirectionGetter.send();
                        }
                    ]]>
                </fx:Script>   
                <s:Label id="lblTest"/>
            </s:Application>

            • 3. Re: Need JSON example for mobile app
              BigZ2011 Level 1

              Perfect - thank you very much!!