欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-11 11:39:54
...
{"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}

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

回复内容:

{"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}

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

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

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

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

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

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

相关标签: php