mb_convert_encoding似乎没有将ASCII转换为UTF-8

时间:2016-03-06 11:16:08

标签: php json encoding utf-8 ascii

我在将JSON ASCII字符串转换为UTF-8时遇到问题。这导致解码字符串时出现问题,因为看起来JSON仅适用于UTF-8。

我已完成以下

$json = '{"success":true,"license_limit":"0","site_count":2,"expires":"lifetime","activations_left":"unlimited","license":"valid","item_name":"Test Item","payment_id":"1717","customer_name":"Test Customer","customer_email":"test@domain.com"}';

echo mb_detect_encoding( $json ); // ASCII

$json =  mb_convert_encoding($json, "UTF-8", mb_detect_encoding( $json ));

$license_data = json_decode( $json );

echo mb_detect_encoding( $json ); // ASCII
echo json_last_error(); // 4 - Invalid Syntax error
echo print_r( $license_data ); // 1

我已经检查了我是否安装了mb_convert_encoding和mb_detect_encoding库(我有),但我很困惑为什么会发生这种情况。有什么想法吗?

0 个答案:

没有答案