我似乎有一个编码问题。我从Twitter API v1.1得到json。JSON字符串看起来很好。它包含表情符号。然后,当我json_decode与PHP,表情符号是不正确的。我忽略了什么?
下面是一个简化的测试用例:
<?php
$json = '{"text":"Here is an emoji 'ud83d"}';
$array = json_decode($json, true);
echo($json); //returns {"text":"Here is an emoji 'ud83d"}
echo($array['text']); //returns Here is an emoji í ½
?>
谢谢你的帮助!
尝试在输出
之前设置字符编码...
header('Content-Type: application/json; charset=utf-8');
echo($json); //returns {"text":"Here is an emoji 'ud83d"}
echo($array['text']); //returns Here is an emoji