C# 处理json字符串中image数据(byte)Base64
2021-06-10 17:02
标签:字节数组 base void image main get 字节 byte enc static void Main(string[] args) C# 处理json字符串中image数据(byte)Base64 标签:字节数组 base void image main get 字节 byte enc 原文地址:https://www.cnblogs.com/WarBlog/p/10594900.html
{
string factString = "中华人民共和国";
byte[] myByte;
string Base64Str;
//先把字符串按照utf-8的编码转换成byte[]
Encoding myEncoding = Encoding.GetEncoding("utf-8");
//myByte中获得这样的字节数组:228,184,173,229,141,142,228,186,186,230,176,145,229,133,177,229,146,140,229,155,189
myByte = myEncoding.GetBytes(factString);
//把byte[]转成base64编码,这个例子形成的base64编码为:"5Lit5Y2O5Lq65rCR5YWx5ZKM5Zu9"
Base64Str = Convert.ToBase64String(myByte);
//再从base64编码转成byte[],又恢复为字节数组:228,184,173,229,141,142,228,186,186,230,176,145,229,133,177,229,146,140,229,155,189
myByte = Convert.FromBase64String(Base64Str);
//用同一个Encoding对象把byte[]转成字符串:"中华人民共和国"
factString = myEncoding.GetString(myByte);
Console.WriteLine(factString);
}
上一篇:wget和curl中使用代理
下一篇:C# XML入门
文章标题:C# 处理json字符串中image数据(byte)Base64
文章链接:http://soscw.com/index.php/essay/93227.html