#
The JSON result is breaking PHPs json_decode. To be exact, the following string is breaking decoding: "Sticky \x26amp; Sweet Tour".
Browsers however seem to be able to understand it: / & /
/ claims it's invalid JSON.
On PHP's side I've tried: and
Any thoughts on what's going on?
https://www.googleapis./freebase/v1/search?query=madonna#
The JSON result is breaking PHPs json_decode. To be exact, the following string is breaking decoding: "Sticky \x26amp; Sweet Tour".
Browsers however seem to be able to understand it: http://jsfiddle/nggX2/ & http://jsfiddle/QUVFt/
http://jsonlint./ claims it's invalid JSON.
On PHP's side I've tried: http://codepad.viper-7./suUbQD and http://codepad.viper-7./QjqCH7
Any thoughts on what's going on?
Share Improve this question edited Jan 3, 2012 at 16:44 Peeter asked Jan 3, 2012 at 16:29 PeeterPeeter 9,3825 gold badges38 silver badges53 bronze badges 5- Why are you trying to decode a string thats not in JSON format? – Michael Commented Jan 3, 2012 at 16:37
- Why do you say it's not in JSON format? – Slavic Commented Jan 3, 2012 at 16:44
-
jsonlint. says invalid for me. I don't think
\x
notation is allowed in JSON. Shouldn't it be\u0026
? – cmbuckley Commented Jan 3, 2012 at 16:48 - It is just a string, it can contain whatever characters you want it to contain. The problem is JSON parser is crashing. It seems this string is ing from/to xml, but that's not the issue. – Kekoa Commented Jan 3, 2012 at 17:29
- What is actually in the database for that value? Is it "Sticky \x26amp; Sweet Tour", "Sticky & Sweet Tour", or "Sticky & Sweet Tour" ? – Kekoa Commented Jan 3, 2012 at 17:38
2 Answers
Reset to default 8What's going on is that this is invalid JSON. The response from that url is incorrect--JSON doesn't allow the \xXX
two-digit hexadecimal binary escape sequences, only \uXXXX
unicode code point escape sequences. Here it should just be &
, though--no escape sequence needed.
No idea why google/freebase is outputting invalid JSON.
Your JSON should look like the following:
"Sticky \\x26amp; SweetTour"
The slash needs to be escaped, because it is the escape char.