8 Replies Latest reply on Sep 26, 2008 8:22 AM by orange_m

    JSON - sign " problem

    orange_m
      Hi all,

      I have returninng string from HTTPrequest:

      [{"id":"20","mesg":"Some message with "content" and something here"}]

      And reading like this:
      var arrViewMsg:Array;
      var jsonStrViewMsg:String = String(event.result.view_msg);

      arrViewMsg = JSON.decode(jsonStrViewMsg);

      And that failed, because of "content". I have tried with slashes \"content\", but I`m getting same problem when JSON is trying to decode.

      Any ideas?
        • 1. Re: JSON - sign " problem
          SujitG Level 2
          Hi,

          What is event.result.view_msg ? event.result will contain the data returned from the server, what is view_msg? Please check if the resultFormat of the HTTPService is text.

          Hope this helps.
          • 2. Re: JSON - sign " problem
            orange_m Level 1
            PHP script return:

            <view_msg>$json->encode($msg)</view_msg>

            Looks like

            <view_msg>[{"id":"20","mesg":"Some message with "content" and something here"}]</view_msg>

            Json decode is confused on Flex side when double quotes are in the string. There must be some way to escape it...

            Btw. It works great without quotes in the text.
            • 3. Re: JSON - sign &quot; problem
              SujitG Level 2
              Hi,

              Please find the string with double quotes escaped. Try to avoid double quotes in the string, try single quotes instead.

              [{"id":"20","mesg":"Some message with \\\"content\\\" and something here"}]

              Hope this helps
              • 4. Re: JSON - sign &quot; problem
                orange_m Level 1
                This is working, with extra slashes. Thank you for suggestion.

                But, this way I`m getting extra slashes in the flex, so I have to strip them again.

                What do you think is it better way to get that data without JSON, and avoid all these "slash problems".

                For example:


                <message>
                <id>20</id>
                <mesg>Some message with "content" and something here</mesg>
                </message>

                event.result.message.id
                event.result.message.mesg

                • 5. Re: JSON - sign &quot; problem
                  Level 7

                  "orange_m" <webforumsuser@macromedia.com> wrote in message
                  news:gbilgh$6ib$1@forums.macromedia.com...
                  > This is working, with extra slashes. Thank you for suggestion.
                  >
                  > But, this way I`m getting extra slashes in the flex, so I have to strip
                  > them
                  > again.
                  >
                  > What do you think is it better way to get that data without JSON, and
                  > avoid
                  > all these "slash problems".
                  >
                  > For example:
                  >
                  >
                  > <message>
                  > <id>20</id>
                  > <mesg>Some message with "content" and something here</mesg>
                  > </message>
                  >
                  > event.result.message.id
                  > event.result.message.mesg

                  CDATA?


                  • 6. Re: JSON - sign &quot; problem
                    orange_m Level 1
                    This is CDATA:

                    event.result.message.id
                    event.result.message.mesg

                    This is response from script:

                    <message>
                    <id>20</id>
                    <mesg>Some message with "content" and something here</mesg>
                    </message>
                    • 7. Re: JSON - sign &quot; problem
                      Level 7

                      "orange_m" <webforumsuser@macromedia.com> wrote in message
                      news:gbiq97$c3h$1@forums.macromedia.com...
                      > This is CDATA:
                      >
                      > event.result.message.id
                      > event.result.message.mesg
                      >
                      > This is response from script:
                      >
                      > <message>
                      > <id>20</id>
                      > <mesg>Some message with "content" and something here</mesg>
                      > </message>

                      Have the script wrap the problem content in CDATA


                      • 8. Re: JSON - sign &quot; problem
                        orange_m Level 1
                        It is working fine, but I`m asking is it better approcach than JSON (since JSON is making me problems with double quotes).