Invalid JSON : Invisible Chars?
I am using JSON to go between PHP and Javascript/Jquery... and for some reason the data I am pulling out of a MSSQL table is intermittenly making my JSON invalid. I cannot see any reason why this should be invalid... and the same set of data works fine for OTHER entries. I've tried different char encodings... I have tried using htmlentities() and htmlspecialchars() and certian entries still render the JSON开发者_如何学Go invalid.
Here is an example of invalid JSON
{"TASK": "test","TYPE": "Other Issue","SUBTYPE": "","CATEGORY": "","REQUEST": "Mat Gilbert","OPENDATE": "Dec 8 2010 5:12PM","PRIORITY": "2 - Low","DUEDATE": "","DESCRIPT": "12/8/2010 12:12 PM Eastern Standard Time - scldom\mgilbert test\n","STATUS": "","RESPONS": ""}
When I use jsonlint... it tells me the following:
syntax error, unexpected TINVALID at line 10
Line 10 is the "DESCRIPT" field.
I'm totally lost as to why this is invalid JSON. Please help.
You have to escape this slash scldom\mgilbert
like so scldom\\mgilbert
.
To save yourself future trouble generating proper JSON, you can use PHP's json_encode()
function.
This:
scldom\mgilbert
\m
is invalid. Change it to \\m
精彩评论