'&' in json data

'&' in json data

mesler4mesler4 Posts: 2Questions: 0Answers: 0
edited January 2010 in General
I'm using server-side processing and some of my returned data has an '&' in the middle of the string (ie. test&test). When displayed, the string is truncated starting at the '&'. I tried encoding/decoding the string, but still no luck. Any suggestions would be appreciated!

Thanks,
Michelle

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Michelle,

    Can you post a link to an example showing the problem please. In just plain json '&' shouldn't be a problem. Also worth running your json through http://jsonlint.com .

    Thanks,
    Allan
  • mesler4mesler4 Posts: 2Questions: 0Answers: 0
    Allan,

    Here's an example of the data I'm sending:

    {
    "sEcho": 1,
    "iTotalRecords": 1,
    "iTotalDisplayRecords": 1,
    "aaData": [
    [
    "SS TEST&TEST",
    " ",
    " ",
    " ",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    " "
    ]
    ]
    }

    Thanks,
    Michelle
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Michelle,

    Perhaps the correct thing to do would be to escape the HTML entities in the string. Are you using PHP? If so you could just use the htmlspecialchars() function - http://php.net/manual/en/function.htmlspecialchars.php . Hopefully that will do the trick for you. I suspect different browsers might well have different behaviour for this as well - injecting an unescaped entity via innerHTMl.

    Regards,
    Alllan
This discussion has been closed.