DirtyBirdNJ
DirtyBirdNJ

Reputation: 592

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 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.

Upvotes: 2

Views: 381

Answers (2)

Mike Thomsen
Mike Thomsen

Reputation: 37506

This:

scldom\mgilbert

\m is invalid. Change it to \\m

Upvotes: 2

vls
vls

Reputation: 2319

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.

Upvotes: 5

Related Questions