解决json_encode中文乱码情况
生活随笔
收集整理的這篇文章主要介紹了
解决json_encode中文乱码情况
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大家經常會遇到使用json_encode轉成json格式時,中文會變成urlencode格式:\u9017\u6bd4\u8bfa\u59d0.
現在提供一種解決方法:
? ? ?在json_encode之前使用urlencode轉一下,然后返回的數據json_decode后再使用urldecode轉回來
例子:
<?php??
????$testJSON=array('name'=>'中文字符串','value'=>'test');??
????//echo?json_encode($testJSON);??
????foreach?(?$testJSON?as?$key?=>?$value?)?{??
????????$testJSON[$key]?=?urlencode?(?$value?);??
????}??
????echo?urldecode?(?json_encode?(?$testJSON?)?);??
?>??
總結
以上是生活随笔為你收集整理的解决json_encode中文乱码情况的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lg-1 x 怎么算_神仙同框!周杰伦x
- 下一篇: 学习《图说设计模式》建造者模式