admin管理员组文章数量:1317909
#
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.
本文标签: javascriptJSON with x26 in values breaks PHPs jsondecodeStack Overflow
版权声明:本文标题:javascript - JSON with x26 in values breaks PHPs json_decode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742022486a2414933.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论