'&' in json data
'&' in json data
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
Thanks,
Michelle
This discussion has been closed.
Replies
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
Here's an example of the data I'm sending:
{
"sEcho": 1,
"iTotalRecords": 1,
"iTotalDisplayRecords": 1,
"aaData": [
[
"SS TEST&TEST",
" ",
" ",
" ",
"",
"",
"",
"",
"",
"",
"",
" "
]
]
}
Thanks,
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