首頁 >後端開發 >php教程 >php的json接口转码问题?不知道哪里错误了弄出来都是乱码

php的json接口转码问题?不知道哪里错误了弄出来都是乱码

WBOY
WBOY原創
2016-06-06 20:15:56882瀏覽

<code>{"appid":"assdf","appsecret":"56d0626167e58ee3770021b6","itemdata":{"nType":"1","nBaoYou":"0","szItemId":"520361590788","title":"韩版夏季韩国大码无袖T恤宽松短裤女休闲学生跑步运动套装两件套","secondTitle":"","imgURL":"http:\/\/img4.tbcdn.cn\/tfscom\/i1\/TB1wJnVIpXXXXcHXFXXXXXXXXXX_!!0-item_pic.jpg","promotionTxt":"继续狂欢节","fOldPrice":"58","fThirdPrice":"19.9","fCommissionPer":"12.3","fCommission":"2.45","nTgCount":"1","nSellCount":"-1","fPingFen":"-1","nPingjiaCount":"-1","szTgURL":"http:\/\/s.click.taobao.com\/NT7PEcx","szWebTgURL":"","szBlogTgURL":"","shortUrl":"http:\/\/s.click.taobao.com\/NT7PEcx","szDesc":""}\r\n}
</code>

这个是在PHP端ECHO 出来的.但是变成这样?不知道哪里解码错误了,中文给解码出来了,但是引号好像变成了其他东西,思路比较模糊,希望做过的人给个清晰的思路

回复内容:

<code>{"appid":"assdf","appsecret":"56d0626167e58ee3770021b6","itemdata":{"nType":"1","nBaoYou":"0","szItemId":"520361590788","title":"韩版夏季韩国大码无袖T恤宽松短裤女休闲学生跑步运动套装两件套","secondTitle":"","imgURL":"http:\/\/img4.tbcdn.cn\/tfscom\/i1\/TB1wJnVIpXXXXcHXFXXXXXXXXXX_!!0-item_pic.jpg","promotionTxt":"继续狂欢节","fOldPrice":"58","fThirdPrice":"19.9","fCommissionPer":"12.3","fCommission":"2.45","nTgCount":"1","nSellCount":"-1","fPingFen":"-1","nPingjiaCount":"-1","szTgURL":"http:\/\/s.click.taobao.com\/NT7PEcx","szWebTgURL":"","szBlogTgURL":"","shortUrl":"http:\/\/s.click.taobao.com\/NT7PEcx","szDesc":""}\r\n}
</code>

这个是在PHP端ECHO 出来的.但是变成这样?不知道哪里解码错误了,中文给解码出来了,但是引号好像变成了其他东西,思路比较模糊,希望做过的人给个清晰的思路

json_encode添加第二个参数,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE,所有的转义和中文字符就可以保持不变

是用的json_encode()函数把数组转成json么?

只是另外吧双引号 转成了'& quot;'

你在json_encode后才进行符号转义
应该在数组时就进行内容的转义,然后json_encode

json_encode 之前的数据什么样子的?

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