8 Replies Latest reply on Jul 26, 2011 8:35 PM by flexy8

    Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]

    flexy8 Level 1
      Main Thread (Suspended: ReferenceError: Error #1065: Variable com.adobe.serialization.json::JSON is not defined.)     
           Test/onLoad     
           flash.events::EventDispatcher/dispatchEventFunction [no source]     
           flash.events::EventDispatcher/dispatchEvent [no source]     
           flash.net::URLLoader/onComplete [no source]     
      
       
      

       

       

       

      I get the above stack everytime a JSON file is decoded even though it's defined both as namespace and as an "import" on a script...

       

       

       

      xmlns:json="com.adobe.serialization.json.*"
      AND
      import com.adobe.serialization.json.JSON;
      

       

       

       

      [UPDATE]

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark" 
                                  xmlns:mx="library://ns.adobe.com/flex/mx"
                                  xmlns:json="com.adobe.serialization.json.*">
           
           <s:layout>
                <s:HorizontalLayout/>
           </s:layout>
           
           <fx:Script>
                <![CDATA[
                     import com.adobe.serialization.json.JSON;
                     
      
                     private function readJSON():void {
                          var odLoader:URLLoader = new URLLoader();
                          odLoader.load(new URLRequest("json.txt"));
                          odLoader.addEventListener(Event.COMPLETE, onLoad);
                     }
                     
                     private function onLoad(event:Event):void {
                          var jsonData:Object = JSON.decode(event.target.data);
                          trace(jsonData);
                     }
                     
                     
                     protected function tickBtn_clickHandler(event:MouseEvent):void
                     {
                          readJSON();
                     }
                ]]>
           </fx:Script>
           
           <fx:Declarations>
                <!-- Place non-visual elements (e.g., services, value objects) here -->
           </fx:Declarations>
           
           <s:Button id="tickBtn" click="tickBtn_clickHandler(event)" label="Tick!"/>
      </s:WindowedApplication>
      
       
      

       

       

      Message was edited by: flexy8

        • 1. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
          Flex harUI Adobe Employee

          Importing is not enough, you need a class declaration.  Try

              import com.adobe.serialization.json.JSON; JSON;

          • 2. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
            flexy8 Level 1

            I did it but still gives me the same error.

            • 3. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
              Flex harUI Adobe Employee

              Generate a -link-report and see if the class is linked in.

              • 4. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
                flexy8 Level 1

                This is the code snippet of the report where the JSON class is seen...

                 

                 <script name="C:\...\src\Test.mxml" mod="1311703824634" size="4572" optimizedsize="3447">
                      <def id="Test" />
                      <pre id="flash.events:IEventDispatcher" />
                      <pre id="spark.components:WindowedApplication" />
                      <dep id="mx.styles:CSSSelector" />
                      <dep id="flash.events:Event" />
                      <dep id="mx.styles:CSSStyleDeclaration" />
                      <dep id="spark.components:TextInput" />
                      <dep id="mx.core:DeferredInstanceFromFunction" />
                      <dep id="com.adobe.serialization.json:JSON" />
                      <dep id="flash.net:URLRequest" />
                      <dep id="spark.components:Button" />
                      <dep id="_Test_Styles" />
                      <dep id="mx.core:mx_internal" />
                      <dep id="spark.layouts:HorizontalLayout" />
                      <dep id="mx.binding:BindingManager" />
                      <dep id="mx.styles:CSSCondition" />
                      <dep id="mx.core:IFlexModuleFactory" />
                      <dep id="flash.events:MouseEvent" />
                      <dep id="AS3" />
                      <dep id="_Test_FlexInit" />
                      <dep id="flash.net:URLLoader" />
                      <dep id="mx.events:PropertyChangeEvent" />
                    </script>
                

                 

                 

                and

                 

                 

                    <ext id="flash.text:TextLineMetrics" />
                    <ext id="flash.utils:getQualifiedSuperclassName" />
                    <ext id="com.adobe.serialization.json:JSON" />
                    <ext id="flash.events:HTTPStatusEvent" />
                    <ext id="flash.geom:PerspectiveProjection" />
                    <ext id="flash.text.engine:DigitWidth" />
                  </external-defs>
                </report>
                

                 

                 

                I don't understand this codes as to what you've referred to as linked...

                • 5. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
                  Flex harUI Adobe Employee

                  Use -link-report testlinkreport.txt

                   

                  The file testlinkreport.txt should show up in the output folder.  Open it

                  and search for the JSON class.  If it is in the external definitions list

                  that would explain why you're getting the error, then you have to figure out

                  why it is being externalized.

                  1 person found this helpful
                  • 6. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
                    flexy8 Level 1

                    Thanks!! We're almost there. The "definition" error is now gone as I've come to change the "Link type" to "Merge into code" instead of "External"..

                     

                    However, this the new error:

                     

                    JSONParseError: Unexpected e encountered
                         at com.adobe.serialization.json::JSONTokenizer/parseError()[/Users/ccantrel/Projects/google/as3corelib/src/com/adobe/serialization/json/JSONTokenizer.as:698]
                         at com.adobe.serialization.json::JSONTokenizer/getNextToken()[/Users/ccantrel/Projects/google/as3corelib/src/com/adobe/serialization/json/JSONTokenizer.as:214]
                         at com.adobe.serialization.json::JSONDecoder/nextToken()[/Users/ccantrel/Projects/google/as3corelib/src/com/adobe/serialization/json/JSONDecoder.as:102]
                         at com.adobe.serialization.json::JSONDecoder/parseObject()[/Users/ccantrel/Projects/google/as3corelib/src/com/adobe/serialization/json/JSONDecoder.as:195]
                         at com.adobe.serialization.json::JSONDecoder/parseValue()[/Users/ccantrel/Projects/google/as3corelib/src/com/adobe/serialization/json/JSONDecoder.as:297]
                         at com.adobe.serialization.json::JSONDecoder()[/Users/ccantrel/Projects/google/as3corelib/src/com/adobe/serialization/json/JSONDecoder.as:72]
                         at com.adobe.serialization.json::JSON$/decode()[/Users/ccantrel/Projects/google/as3corelib/src/com/adobe/serialization/json/JSON.as:81]
                         at WPAOSDesktop/onLoad()[C:\Users\Ed\Adobe Flash Builder 4.5\WPAOSDesktop\src\WPAOSDesktop.mxml:23]
                         at flash.events::EventDispatcher/dispatchEventFunction()
                         at flash.events::EventDispatcher/dispatchEvent()
                         at flash.net::URLLoader/onComplete()
                    

                    • 7. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
                      Flex harUI Adobe Employee

                      Looks like the JSON string has some unexpected data in it.

                      • 8. Re: Could not decode JSON in Flex 4.5.1 [UPDATED w/ full source code]
                        flexy8 Level 1

                        I didn't expect that a Google API would provide an invalid format of a JSON file. It doesn't put double quotes on it's element names.. just the values of it.

                         

                        So I'm gonna do a little RegExp on it first before doing JSON decoding.

                         

                        Thanks for the big help!