2 Replies Latest reply on Mar 8, 2007 11:04 AM by Xygar

    corelib and JSON woes

      I would like to serialize the data contained in an ArrayCollection using JSON. Unfortunately, I keep getting a stack overflow error when I try and JSON.encode() an array. I tried using the ArrayCollection.toArray() and I tried just creating a simple array of objects. I can't seem to get it to work.

      If I do this: JSON.encode({prop1:"hello", prop2:"hello"}); it works just fine.

      What am I doing wrong? Anyone know?

      BTW, I'm not entirely sure I linked the library up correctly. I couldn't find any great examples. What I did was add <path-element>../corelib/bin</path-element> to my flex-config.xml file and added import com.adobe.serialization.json.JSON; to my script.

      PS. I don't have Flex Builder. I'm using the command line compiler.
        • 1. Re: corelib and JSON woes
          michael_ramirez44 Level 1
          I use "-compiler.library-path+=" command line argument to include external libraries into my Flex projects. I can't help you with the JSON because I have never used it before.
          • 2. Re: corelib and JSON woes
            Xygar Level 1
            It turns out that it was a problem with my array. I was looping through an XMLList to build the array.

            Here is how I was building it, inside of the result event for an HTTPService:

            var xmlList:XMLList = event.result.caption;
            for each ( var xml:XML in xmlList ) {
            myArrayCollection.addItem({id:xml.@id, text:xml.text, time:xml.time})

            The JSON encoder was choking on the object's property types (I'm not sure what they are, I didn't look. Maybe XML text nodes?). By type casting the xml values, everything works fine:

            var xmlList:XMLList = event.result.caption;
            for each ( var xml:XML in xmlList ) {
            myArrayCollection.addItem({id:String(xml.@id), text:String(xml.text), time:String(xml.time)})

            Thanks for the compiler argument. That is more flexible than editing the configuration file.