开发者

PHP Json decoder returns NULL if it contains & or é or special characters

I'm wondering how to escape these special characters for the php built-in json decoder to understand, and what are these characters?

Example: json_decode('{"text":"test & test"}',true);

开发者_StackOverflow社区Returns NULL

I try to use \ to escape it but it doesn't work ( only works for quotes ).

Any solution?


It should work with using plain & it works for me so ... , however i had problems in the past with with stings that didn't recognize some special characters , the solution in that case was to make shure that the php file document encoding was set to utf8 . Another problem i had in the past was with XMLReader witch didn't accept a plain simple & but & instead works just fine so you could try the following :

json_decode(preg_replace('/&/','&','{"text":"test & test"}'));

p.s. i suppose you're trying to decode a larger json string so the problem might come from a different part of the string , did you run the exact test you posted in the question and it returned null ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜