2 Replies Latest reply on Jul 2, 2008 10:35 AM by Joey-ATL

    JSON.decode not working

    Joey-ATL Level 1
      I am using the corelib version 0.9 to use JSON.

      This is the string I am trying to decode: {xaxis:["test1","test2","test3","test4","test5"]}

      That string is called strColumns and I am using this command: JSON.decode( strColumns )

      This is the full command line: columns:Array = (JSON.decode( strColumns ) as Array);

      I want to be able to do this: columns.xaxis[0]; // which should equal "test1"

      And I am getting this error:

      Error: Unexpected x encountered
      at com.adobe.serialization.json::JSONTokenizer/parseError()

      I can see this error all over the Net where other people have had the same problems but no one has found/provided a fix for it. Does anyone have any ideas/solutions?

      Thanks in advance.

        • 1. Re: JSON.decode not working
          atta707 Level 2
          You property name -- xaxis in this case -- must be a quoted string:

          private function decode() : void {
          var s:String = '{ "xaxis":["test1","test2","test3","test4","test5"]}';
          var o:Object = JSON.decode(s);
          var a:Array = o['xaxis'] as Array;


          • 2. JSON.decode not working
            Joey-ATL Level 1
            That was it!
            I put a "watch" on this line: var o:Object = JSON.decode(s);
            and saw that the "o" object had a member called "xaxis" that was of type Array. So, your answer gave me exactly what I was looking for. Thanks.