PHP decoding and encoding json with unicode characters

前端 未结 8 1016
野性不改
野性不改 2020-11-27 17:46

I have some json I need to decode, alter and then encode without messing up any characters.

If I have a unicode character in a json string it will not decode. I\'m n

8条回答
  •  不知归路
    2020-11-27 18:36

    try setting the utf-8 encoding in your page:

    header('content-type:text/html;charset=utf-8');
    

    this works for me:

    $arr = array('tag' => 'Odómetro');
    $encoded = json_encode($arr);
    $decoded = json_decode($encoded);
    echo $decoded->{'tag'};
    

提交回复
热议问题