You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

含Unicode的API响应转CSV后Excel显示乱码,如何解决?

问题:Unicode字符转CSV后显示乱码的处理方案

我的程序从外部API接收包含Unicode转义字符的字符串响应,比如\u2019(对应单引号’)、\u2014(对应长破折号—),示例内容如下:

it\u2019s often these details that make the driving experience not just functional but pleasurable. Investing time in choosing the right wiper refill is akin to dotting the i's and crossing the t's\u2014once done, it\u2019s immensely satisfying.

之后我用以下C#代码将字符串转换为CSV:

private static string ConvertToCsv(List<CsvResponse> records)
{
    using (var writer = new StringWriter())
    using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
    {
        csv.WriteRecords(records);
        return writer.ToString().TrimEnd('\r','\n');
    }
}

转换完成后,CSV里的Unicode字符变成了乱码,比如原字符串中的it\u2019s变成了it’s,请问该如何解决这个问题?


更新说明

感谢各位的实用建议!我已经排查出问题根源:这是Excel等CSV读取工具的编码识别问题,只需给CSV添加**字节顺序标记(Byte Order Mark, BOM)**即可解决。再次感谢大家!

内容的提问来源于stack exchange,提问作者roxiehehe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.01 13:27:30