【发布时间】:2022-01-06 18:18:08
【问题描述】:
我有以下程序:
#! /usr/bin/perl
use strict;
use warnings;
use utf8;
print "\x{00a0}\n";
当我运行它时,它会产生错误的 UTF-8 编码:
$ ./nbsp.pl | od -tx1
0000000 a0 0a
0000002
我的期望是这样的:
$ printf '\u00a0\n' | od -tx1
0000000 c2 a0 0a
0000003
为什么00a0 编码为a0 而不是应该的c2a0?
当我尝试解析 JSON 数据时,也会发生同样的情况:
#! /usr/bin/perl
use strict;
use warnings;
use JSON::Parse qw(parse_json);
my $json = parse_json ('{"nbsp":"\u00A0"}');
print $json->{nbsp}, "\n";
【问题讨论】: