2011-10-31 47 views
0

海兰,解码串XML

我想解码包含在.NET XML数据的字符串,但该字符串是在Java编码

System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); 
System.Text.Decoder utf8Decode = encoder.GetDecoder(); 
byte[] todecode_byte = Convert.FromBase64String(data); 
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); 
char[] decoded_char = new char[charCount]; 
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); 
result = new String(decoded_char); 
return result; 

我写了代码,但它抛出错误。 在此先感谢。

+1

什么是错误? –

+6

对于所有二元的爱,请提供错误。 – ChaosPandion

+0

输入不是有效的Base-64字符串,因为它包含非基本64字符,两个以上填充字符或填充字符中的非空白字符。 – jats

回答

2

假设它确实是UTF-8,然后base64编码,你应该能够编写:

byte[] binary = Convert.FromBase64String(data); 
string text = Encoding.UTF8.GetString(binary); 

但是,它听起来就像是不是 base64编码下手 - 如果你已经把它作为文本,你应该可以使用它,而不需要额外的工作。