1

我有一个文本,它是一个对象的属性。对象得到 XmlSerialized,之后 XML 调用 Text 中有一个元素表示来自对象的文本。我想知道如何将其转回字符串。

序列化类型XmlSerializer serizlizer = new XmlSerializer(typeof(Act));

类中的属性

[System.Runtime.Serialization.OptionalFieldAttribute()]
private byte[] ActTextField;

在 xml 文件中,它看起来像这样:

0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAALQAAAAAAAAAAEAAALwAAAAEAAAD+////AAAAACwAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////spcEAJ2AJBAAA8BK/AAAAAAAAEAAAAAAABgAAYB4AAA4AYmpiavbg9uAAAAAAAAAAAAAAAAAAAAAAAAACBBYALiIAAJSKAQCUigEAzwYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAKQAAAAAANADAAAAAAAA0AMAANADAAAAAAAA0AMAAAAAAADQAwAAAAAAANADAAAAAAAA0AMAABQAAAAAAAAAAAAAAOQDAAAAAAAArAgAAAAAAACsCAAAAAAAAKwIAAAAAAAArAgAABQAAADACAAAFAAAAOQDAAAAAAAA/Q4AALYAAADgCAAAAAAAAOAIAAAAAAAA4AgAAAAAAADgCAAAAAAAAOAIAAAAAAAA4AgAAAAAAADgCAAAAAAAAOAIAAAAAAAAWA4AAAIAAABaDgAAAAAAAFoOAAAAAAAAWg4AAAAAAABaDgAAAAAAAFoOAAAAAAAAWg4AACQAAACzDwAAaAIAABsSAACSAAAAfg4AADkAAAAAAAAAAAAAAAAAAAAAAAAA0AMAAAAAAADgCAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgCAAAAAAAA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8EIAAgACAEIAAgABUEIAAgABQEIAAgABUEIAAgABsEIAAgABUEIAAgAB0EIAAgABgEIAAgABUEIAANABUELgAgAEAEMAQ5BD4EPQQ1BD0EIABBBEoENAQgADIEIAA3BDAEOgRABDgEQgQ+BCAAQQRKBDQENQQxBD0EPgQgADcEMARBBDUENAQwBD0EOAQ1BCAAPQQwBCAANAQyBDAENAQ1BEEENQRCB

我什至不知道它的编码是什么以及如何解码它。我试图将它读入字节数组,但在应用了一些解码Encode.UTF8 , Encode.ASCII后它实际上并没有工作。

4

1 回答 1

3

对我来说这看起来像 Base64 - 只需使用

byte[] data = Convert.FromBase64String(base64Text);

如果这确实是一个文本属性,那么它完全使用 base64 是很奇怪的。我希望只有文字。

要将二进制数据转换回文本,您需要知道使用哪种编码将其转换为二进制数据以开始 - 最有可能的是 UTF-8 - 但其中所有重复的AAAAA...部分使这看起来与文本非常不同, 老实说。

编辑:现在我们已经看到了字段声明,我们可以看到它是一byte[]开始的,因此以这种方式对其进行编码是有意义的。从评论来看,听起来它实际上是一个 Word 文件——此时提取文本是一个非常独立的问题。

于 2013-08-12T07:40:53.500 回答