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
    Gainesville, FL


    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:
    Read the comments, it'll help you really understand it.
    Read the "Unsafe" section
    Read section 2.2
    Just a good page to see different character codes
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:

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

  4. #4


    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