请教数组的序列化问题。(50分)

月影 月影 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
使用如下代码序列化一个字符串数组:

string[] a = new string[] { "aa", "bbb" };
DataContractSerializer ser = new DataContractSerializer(typeof(string[]), "root", "");
using (MemoryStream ms = new MemoryStream())
{
ser.WriteObject(ms, a);
ms.Position = 0;
using (StreamReader reader = new StreamReader(ms))
{
string sss = reader.ReadToEnd();
}
}


得到sss的内容是:
<root xmlns:d1p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d1p1:string>aa</d1p1:string>
<d1p1:string>bbb</d1p1:string>
</root>

请问,如何才能把默认的命名空间去掉呢?
我希望得到的结果是:
<root xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<string>aa</string>
<string>bbb</string>
</root>

等待高手指教。 谢谢。
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
月影
C# 111,129 成员 642,538 内容