首頁 >後端開發 >php教程 >json数据中有特殊字符,该如何处理

json数据中有特殊字符,该如何处理

WBOY
WBOY原創
2016-06-06 20:31:281781瀏覽

有一json如:{"user_info_list":[{"subscribe":1,"nickname":"梁","city":"","province":"巴黎","country":"法国","groupid":0},{"subscribe":1,"nickname":"默笙","city":"O[\q","province":"^N","country":"","groupid":0}]} 用json_decode函数转化为null,原因是"city":"O[\q","province":"^N"受这些影响。该对诸如此类的字符有什么解决的办法没

回复内容:

有一json如:{"user_info_list":[{"subscribe":1,"nickname":"梁","city":"","province":"巴黎","country":"法国","groupid":0},{"subscribe":1,"nickname":"默笙","city":"O[\q","province":"^N","country":"","groupid":0}]} 用json_decode函数转化为null,原因是"city":"O[\q","province":"^N"受这些影响。该对诸如此类的字符有什么解决的办法没

把字符串里的\转义

如果是字符串 就要变成\\\\

<code>var_dump(json_decode('{"city": "O[\\\\q"}'));
</code>

json_decode函数是什么东西?

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn