3 Replies Latest reply on Oct 31, 2007 3:33 AM by atta707

    How to send multiple lists to MYSQL via JSON

    dataDash
      I have 3 list which users can add to

      Each item is added to an ArrayCollection
      [Bindable]
      private var arrayKeyPointList:ArrayCollection = new ArrayCollection();

      [Bindable]
      private var arrayBulletPointList:ArrayCollection = new ArrayCollection();

      [Bindable]
      private var arrayQuoteList:ArrayCollection = new ArrayCollection();



      This is one of the functions which is called when a user wants to add an item:
      private function addBulletPointToList():void
      {
      if (txtNewBulletPoint.text != ""){
      arrayBulletPointList.addItemAt(txtNewBulletPoint.text,0);
      txtNewBulletPoint.text = "";
      }
      }

      When they have filled in the 3 lists they hit the send button. The code below is for testing purposes only.

      private function sendNewProduct():void
      {
      var sendData:Array = new Array();

      sendData.push({keypoints:arrayKeyPointList.toArray()}, {bulletpoints:arrayBulletPointList.toArray()}, {quotes:arrayQuoteList.toArray()});

      var jsonSendData:String = JSON.encode(sendData)
      //jsonSendData = escape(jsonSendData);

      Alert.show(jsonSendData);
      }

      Am I doing this correctly, is there a better way? Also if I change the add function to:

      private function addBulletPointToList():void
      {
      if (txtNewBulletPoint.text != ""){
      arrayBulletPointList.addItemAt({bulletpoint:txtNewBulletPoint.text},0);
      txtNewBulletPoint.text = "";
      }
      }

      I get this JSON output

      [{"keypoints":[]},{"bulletpoints":[{"bulletpoint":"test bullet point","mx_internal_uid":"8F1AAB73-0783-132B-EE43-F1F4F29284FA"}]},{"quotes":[]}]

      although the mx_internal_uid are not a problem it does mean I'm sending more data than is necessary, why does it appear and how can I get rid of it, do I need to change the function to at all arrayBulletPointList.addItemAt({bulletpoint:txtNewBulletPoint.text},0); or just leave it as arrayBulletPointList.addItemAt(txtNewBulletPoint.text,0);

      Many thanks!
        • 1. Re: How to send multiple lists to MYSQL via JSON
          atta707 Level 2
          Ever wondered how would flex keep track for elements added to arraycollection? And I'm sure you know about dynamic keyword and that Object class is already dynamic and that the syntax you've just used to construct a JSON object is an example of building dynamic objects.

          with this background, mx_internal_uid is flex's way to tell one object from another while for example searching for some object in the array collection.

          wan to get rid of it? take a look at IUID interface.

          hope this helps.

          ATTA
          • 2. Re: How to send multiple lists to MYSQL via JSON
            dataDash Level 1
            Thanks for the reply, I think I understand why Flex is using the uid to keep track of the information. You have lost me a bit with the dynamic keywords as I have only been programming for about a week so still allot to learn! I think I perhaps ask my question wrongly, what I really want to know is, am I sending multiple arrays correctly using JSON is there another way? Thanks again for your reply.
            • 3. Re: How to send multiple lists to MYSQL via JSON
              atta707 Level 2
              I don't see any problem with the way you're pushing multiple arrays into JSON and hoping that you're actually them right on the server side.

              ATTA