值为\ x26的JSON会破坏PHP json_decode [英] JSON with \x26 in values breaks PHPs json_decode
问题描述
https://www.googleapis.com/freebase/v1/search ?query = madonna#
JSON结果正在破坏PHP json_decode。确切地说,以下字符串正在破解:Sticky \x26amp; Sweet Tour。
浏览器似乎能够理解它: http:/ /jsfiddle.net/nggX2/ & http://jsfiddle.net/QUVFt/
http://jsonlint.com/ 声称它是无效的JSON。
在PHP方面,我尝试过: http://codepad.viper-7.com/suUbQD 和 http://codepad.viper-7.com/QjqCH7
有什么想法?
发生的是这是无效的JSON。该URL的响应不正确--JSON不允许 \xXX
两位十六进制转义序列,只有 \uXXXX
unicode码点转义序列。这里它应该只是&
,但不需要转义序列。
不知道为什么google / freebase正在输出无效的JSON。
https://www.googleapis.com/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.net/nggX2/ & http://jsfiddle.net/QUVFt/
http://jsonlint.com/ claims it's invalid JSON.
On PHP's side I've tried: http://codepad.viper-7.com/suUbQD and http://codepad.viper-7.com/QjqCH7
Any thoughts on what's going on?
What'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.
这篇关于值为\ x26的JSON会破坏PHP json_decode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!