jjzjj

serialization

全部标签

c# - XmlSerializer 反序列化 CSC.EXE 的错误

我创建了一个在我的计算机上运行良好并且通常在其他计算机上也运行良好的程序。但是有人在运行它时遇到问题,我真的不明白为什么,Stacktrace是:System.Runtime.InteropServices.ExternalException(0x80004005):Impossibileeseguireunprogramma.Ilcomandoinesecuzioneera"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe"/noconfig/fullpaths@"C:\Users\Andry\AppData\Local\

c# - 我不能在序列化/反序列化中使用 XmlElementAttribute.IsNullable

这是我要序列化/反序列化的类。publicclassMyDic{...[XmlElement(IsNullable=true)]publicListWebDefinitions;...}它是结构WebDefinition的完整定义。publicstructWebDefinition{publicstringDefinition;publicstringURL;publicWebDefinition(stringdef,stringurl){Definition=def;URL=url;}publicoverridestringToString(){returnthis.Definiti

c# - 如何在 XML 中序列化对象,同时展平属性的内部层次结构

我正在使用XmlSerializer序列化一个对象,在我的对象中指定属性以向XmlSerializer发出指令,如下所示:[XmlType("FooElement")]publicclassFoo{[XmlAttribute("Type")]publicstringfooType;[XmlElement("Name")]publicstringName;[XmlElement("Bar")]publicBarBarObject;}publicclassBar{[XmlElement("Message")]publicstringBarString;[XmlElement("From")

c# - C# 中的 XML 反序列化数组

我已经尝试了所有无法反序列化此XML文档的方法。00175565KJAAM-EMC16x(2+1)x0,5T500st253740000175565100175565000304132313315331833160486.2这是反序列化的方式[Serializable()]publicclassitem{[System.Xml.Serialization.XmlElement("id")]publicstringID{get;set;}[System.Xml.Serialization.XmlElement("descr")]publicstringDescr{get;set;}[Sy

c# - 如何在没有模式信息的情况下将 c# 对象序列化为 xml?

这个问题在这里已经有了答案:HowcanImakethexmlserializeronlyserializeplainxml?(4个答案)关闭8年前。这是我做的:一个可序列化的类:[Serializable()]publicclassTicket{publicstringCitationNumber{get;set;}publicdecimalAmount{get;set;}}然后将一个模型序列化成xml:varmodel=cart.Citations.Select(c=>newTicket(c.Number,c.Amount)).ToList();varserializer=newX

C# 将内部 XML 反序列化为字符串

我有以下XML:Value1Value2HeadingLorumIpsum这可以通过创建类和添加如下属性在C#中反序列化为XML:[Serializable]publicclassMyType{[XmlElement("MyProperty1")publicstringMyProperty1{get;set;}[XmlElement("MyProperty2")publicstringMyProperty2{get;set;}[XmlIgnore]publicstringMyNestedXml{get;set;}}但是,中的内部XML元素变化并且不遵循一致的结构,我可以使用属性有效地映

c# - 如何重命名 XML 序列化列表 <string> 中使用的子 XML 元素?

我正在将我的类序列化为XML,其中一个属性的类型为List。publicclassMyClass{...publicListProperties{get;set;}...}通过序列化此类创建的XML如下所示:...somethingheresomethinghere...现在是我的问题。我怎样才能改变我的类来实现这样的XML:...somethingheresomethinghere...序列化后。感谢您的帮助! 最佳答案 尝试XmlArrayItemAttribute:usingSystem;usingSystem.IO;usin

xml - 有哪些好的替代序列化格式?

我过去使用过XML,但它非常冗长和笨拙。我们目前正在使用YAML,但我发现大多数开发人员在空格方面遇到了很多麻烦。是否有类似YAML的格式,它对空格不敏感,但不像XML那样冗长? 最佳答案 您没有在YAML中使用空格语法.所有的数据结构也有非空白的替代品,例如序列[1,2,3]和映射{key:value,k:v}。这叫做flowstyle与block样式相反。替代方案可能是JSON,它实际上是YAML的一个子集。它基本上是没有block样式且没有可扩展性的YAML。标准Lisp列表语法(列表由括号分隔,元素由空格分隔)也是一种非常好

c# - XML反序列化为不同的类名

假设我有这个假想的xml:我想反序列化上面的内容。但是我想使用不同的类层次结构反序列化此xml,因为类Schedule、Month和Day在其他地方使用。例如我想要这些类:[XmlRoot("Schedule")publicclassParserSchedule{[XmlElement("Month")]publicListMonth{get;set;}}publicclassParserMonth{[XmlAttribute("name")]publicstringName{get;set;}[XmlElement("Day")]publicListDay{get;set;}}pub

c# - DataTable 或 DataSet 的 XML 反序列化

我有以下XML:我知道这是通过使用newXmlSerializer(typeof(DataTable)).Serialize(writer,(DataTable)myDataTable);序列化DataTable创建的。架构和实际数据可以不同。我需要反序列化它,并尝试了以下方法:reader.ReadStartElement("NewDataSet");vardataSet=(DataTable)newXmlSerializer(typeof(DataTable)).Deserialize(reader);reader.ReadEndElement();还有:reader.ReadSt