json_encode与json_decode

在php中经常使用的函数有json_encode和json_decode,json_encode用于将数组或对象转为字符串,json_decode用于将字符串转换为数组或对象。以下是使用中经常遇到的问题

 

json_encode:

  1、encode时,中文被转码,解决方案:json_encode($arr, JSON_UNESCAPED_UNICODE)

  2、encode时,小数精度丢失,解决方案,将小数转为字符串

 

json_decode:

  1、转为对象, json_decode($str);

  2、转为数组,json_decode($str, true);


    

posted on 2020-11-16 15:26  1450811640  阅读(131)  评论(0编辑  收藏  举报