[英]Decoding Base64 string doesn't translate special chars
I have an XML file encoded as Base64, this file has embeded images in it. 我有一个编码为Base64的XML文件,该文件中嵌入了图像。
My problem is when i try to decode it: 我的问题是当我尝试对其进行解码时:
String sample is here 字符串样本在这里
Here is my code: 这是我的代码:
UTF8 Version: This one can be decoded and loaded into XML but special chars doesn't decode properly (á,é,í,ó,ú,ñ,Ñ) all are decoded as ? UTF8版本:可以将其解码并加载到XML中,但是特殊字符不能正确解码(á,é,í,ó,ú,ñ,Ñ),都被解码为? symbol .
符号 。
public XmlDocument GetXmlDocument(string Base64Text)
{
string DeCoded = string.Empty;
XmlDocument Datos = new XmlDocument();
byte[] Base64 = Convert.FromBase64String(Base64Text);
DeCoded = Encoding.UTF8.GetString(Base64);
Datos.LoadXml(DeCoded);
return Datos;
}
UTF7 Version: This one can be decoded and special chars are all decoded properly. UTF7版本:此字符可以解码,特殊字符都可以正确解码。 If Has images can't be loaded to XML Document due embeded images doesn't decode properly.
如果“由于无法将图像加载到XML文档”,则嵌入的图像无法正确解码。
public XmlDocument GetXmlDocument(string Base64Text)
{
string DeCoded = string.Empty;
XmlDocument Datos = new XmlDocument();
byte[] Base64 = Convert.FromBase64String(Base64Text);
DeCoded = Encoding.UTF7.GetString(Base64);
Datos.LoadXml(DeCoded);
return Datos;
}
EDIT 1: My encoded Base64 string came from VFP app it was encoded using VFP Sintax STRCONV(lcImage, 6) 编辑1:我编码的Base64字符串来自VFP应用,它是使用VFP Sintax STRCONV(lcImage,6)编码的
In VFP help it says:
Converts character expressions between single-byte, double-byte, UNICODE, and locale-specific representations.
And 6 means: 6表示:
6 Converts UNICODE (wide characters) to double-byte characters.
I'm trying with UTF7 and UTF8, just testing wich one could translate my string. 我正在尝试使用UTF7和UTF8,只测试其中一个可以转换我的字符串。
I just need my original XML with it's embeded images in .NET, If this is imposible with standard functions, How can I catch and translate ? 我只需要原始的XML及其在.NET中嵌入的图像,如果标准功能无法实现,该如何捕获和翻译? symbol s to readable chars?
符号 s可读的字符?
From your XML document: 从您的XML文档中:
<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
So, this works: 因此,这有效:
DeCoded = Encoding.GetEncoding(1252).GetString(Base64);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.