当调用我的API时,它会返回视频的标题、描述、图片等。有时我的视频有汉字。所以当我打印出JSON数组时,汉字显示如下:“ \u4e00\u5bb6\u4e0a\u5e02\u4e0d\u4e45\u7684\u5bb6\u5177\u4e1a”。那么我的问题是,调用API并打印出来时,如何打印出中文单词呢? header('Content-Type: text/html; charset=utf-8'); require ("vendor/autoload.php"); use Vimeo\Vimeo; $client = new Vimeo("{client_id}", "{client_secret}", "{access_token}"); $video_id ="xxxxx"; $response = $client->request("/videos/$video_id"); //var_dump($response['body']); if($response['status'] === 200){ header('Content-Type: application/json'); echo json_encode($response['body']); } else { echo json_encode($response['body']['error']); }
1 回答
狐的传说
TA贡献1804条经验 获得超3个赞
与一些参数一起使用json_encode可以防止中文字符的变形。
header('Content-Type: text/html; charset=utf-8');
require ("vendor/autoload.php");
use Vimeo\Vimeo;
$client = new Vimeo("{client_id}", "{client_secret}", "{access_token}");
$video_id ="xxxxx";
$response = $client->request("/videos/$video_id");
//var_dump($response['body']);
if($response['status'] === 200){
header('Content-Type: application/json');
echo json_encode($response['body'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
else {
echo json_encode($response['body']['error']);
}
- 1 回答
- 0 关注
- 129 浏览
添加回答
举报
0/150
提交
取消