How to get json_encode() to work with ISO-8859-1 (åäö)

前端 未结 8 899
礼貌的吻别
礼貌的吻别 2021-01-11 15:58

json_encode() wont work for me when I\'m using åäö. Why? And how can I get it to work?

The php:

echo json_encode($arr);
         


        
8条回答
  •  北荒
    北荒 (楼主)
    2021-01-11 16:51

    As of PHP 5.4.0:

    Convert your strings in your array to into utf-8 using utf8_encode($str) function.

    Then json_encode with JSON_UNESCAPED_UNICODE option:

    $arr = json_encode($array, JSON_UNESCAPED_UNICODE);

提交回复
热议问题