Results 1 to 5 of 5

Thread: encoding spaces in JSON.encode

  1. #1

    Question encoding spaces in JSON.encode

    I am using Ext.util.JSON.encode to serialize a complex object and send it to PHP with Ext.Ajax.request. When I receive it I see that spaces are encoded as plus (+) symbols. Unfortunately a real plus symbol seems to also be encoded as a plus.

    How do I tell a plus from a space in PHP? Is there some encoding option I am missing?

  2. #2

    Default It is happening in the form.getValues, not json encode

    When I do

    var values = Ext.getCmp('detail-tabpanel').getForm().getValues();
    a textfield (at least one) is doing the conversion of spaces to pluses and leaving pluses as pluses.

    How do I fix this?

  3. #3
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448

    Default

    Looks like '+' is an alias to a space and once a request goes to Apache/PHP it get's decoded.

    So if you send an argument valued at '+ ' then it will be decoded as ' ' (two spaces). What you should probably do is change '+' to it's Hex value '2B' before you send the request. a space's Hex value is '20' and that's why you may see '%20' in the URI in place of spaces.

    I have found a few links for you to help understand this:

    http://bugs.php.net/bug.php?id=39078&edit=1
    Read the comments, it'll help you really understand it.

    http://www.freesoft.org/CIE/RFC/1738/4.htm
    Read the "Unsafe" section

    http://www.ietf.org/rfc/rfc2396.txt
    Read section 2.2

    http://www.asciitable.com/
    Just a good page to see different character codes
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  4. #4

    Default

    Since I posted the original question, I have found out the problem has nothing to do with json or URLs. I am getting this space and plus ambiguity straight from the textarea field in the form immediately upon using form.getValues().

  5. #5

    Smile Solved

    For what it is worth, using getFieldValues() instead of getValues() fixed the problem.

    I'm still confused as to how one would tell the difference between a space and a plus when using getValues().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •