首页 > 其他 > 详细

字符编码

时间:2018-09-15 13:31:24      阅读:185      评论:0      收藏:0      [点我收藏+]

一.问题描述:C#读取json文件中的中文时,出现以下乱码。

???????????????????

1.部分代码展示

var filePath = @"C:\Users\15900\source\repos\Test1\Test1\test_utf8.json";
FileStream pdJson = new FileStream(filePath, FileMode.Open, FileAccess.Read);
using (StreamReader sr = new StreamReader(pdJson))
{
    string str = sr.ReadToEnd();
    Console.WriteLine(str);
    Console.ReadLine();
}

 

二.解决方案

1.Encoding.Default、Encoding.UTF8

...
using (StreamReader sr = new StreamReader(pdJson, Encoding.UTF8))
...

 

技术分享图片

 

2.文件字符编码

 技术分享图片

 

三.总结 

阮一峰.字符编码笔记:ASCII,Unicode 和 UTF - 8  -->  http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html

1.ascii:Amerian Standard Code for Information Interchange

2.unicode: 万国码

3.utf-8:是互联网上使用最广的一种unicode的实现方式

 

Q:

1.System.Text.Encoding, Version = 4.0.10.0 does‘t have Default Property.

字符编码

原文:https://www.cnblogs.com/YaoFrankie/p/9650651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!