jason_encode fails with special characters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    jason_encode fails with special characters

    I have a user that typed the following into an input field

    set 30º

    This data was stored in the table using software other than php.

    Now I am writing some new access code in php and while the data is retrieved from the table correctly, the ajax response returns a null value for that column/field (see photo look for "PRJCTADDR1 ")

    I return a response to the client like so through jason_encode:
    echo json_encode($re s_array);

    The client gets a null value, see attached photo (again look for "PRJCTADDR1 ".

    Is there some standard routine to strip this and other characters from the data stream or otherwise escape these value?

    What values should I be on the lookout for?
    Attached Files
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    Just a followup, just to confirm this is a jason_encode problem. Here is the formatted value of the encode.

    [{...,"PRJCTNAME ":"Proposed Multi-Legged Water Tower","PRJCTADDR1":nul l,.....}]

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      A partial answer is to use htmlentities(st ring) to encode any string to be included in the json response array. However now I need to decode the result on the client where I now get this answer:

      "PRJCTADDR1":"w ith Legs offset 30º"

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        you could try urlencode() in PHP and decodeURICompon ent() in JS.

        Comment

        • Claus Mygind
          Contributor
          • Mar 2008
          • 571

          #5
          Ah! This is occurring in the response to an ajax call in a simple data field. The "htmlentities(s tring)" works very well.

          But the decodeURICompon ent() sounds like a good idea.

          Thanks for your response.

          BTW, you steered me toward EventBug. Seems to be broken with FireFox 8. You got any alternate ideas to put in another great tool like that?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            But the decodeURICompon ent() sounds like a good idea.
            but it can't unescape entities, only %-escapes

            BTW, you steered me toward EventBug. Seems to be broken with FireFox 8. You got any alternate ideas to put in another great tool like that?
            I know it's a bother. currently I don't have a replacement. I only can hope that it will be supported in FF 9+

            Comment

            • Claus Mygind
              Contributor
              • Mar 2008
              • 571

              #7
              Ok thanks, I will work on that

              Comment

              Working...