草庐IT

$序列化

全部标签

c# - 无法反序列化当前的 JSON 数组(例如 [1,2,3])

我正在尝试读取我的JSON结果。这是我的RootObjectpublicclassRootObject{publicintid{get;set;}publicboolis_default{get;set;}publicstringname{get;set;}publicintquantity{get;set;}publicstringstock{get;set;}publicstringunit_cost{get;set;}}这是我的JSON结果[{"id":3636,"is_default":true,"name":"Unit","quantity":1,"stock":"10000

c# - 创建序列的幂集

我正在尝试创建一个程序,该程序是创建序列、字符串或数字的可能组合的基础。这是某种加密/解密程序。我正在使用VisualStudio2013和C#。我想做的是从序列中生成幂集,但我有点困惑,无法继续进行。这是代码。publicstaticvoidrandomSeq(){inttemp=0;stringseq="1234";varsb=newStringBuilder();char[]bits=seq.Select((charc)=>c).ToArray();Console.Write("GivenSequence:");Console.Write(seq);Console.WriteLi

c# - C#中通过XmlSerializer类反序列化多个同名XML元素

我有一个XML格式00010000048010200我需要反序列化它,更改它的内容,然后再将它保存回去。我在阅读ScheduledDay元素时遇到问题。我的课是这样的publicclassBackupScheduleSettings{publicBackupScheduleSettings(){ScheduledDay=newint[7];}.....publicint[]ScheduledDay{get;set;}.....}现在,当我加载具有正确的ScheduledDay值的XML内容时,我的类数组仍然是NULL。我无法修改XML的内容/格式,因为它是遗留代码。我不想使用XDocu

c# - 禁用特定属性的序列化

我有一个用于XML序列化的类对象[XmlType("PAYMENT")]publicclassPaymentXML{[XmlElement(ElementName="REQUEST")]publicRequestXMLRequest{get;set;}[XmlElement(ElementName="META")]publicMetaXMLRequest{get;set;}//PropertythatIdontwanttobeserializedpublicSubscriberSubscriber{get;set;}}序列化varxml=newPaymentXML();stringpa

c# - 更改用于 XML 序列化的 XmlElement 名称

我们有以下代码:[Serializable]publicclassClass1{[XmlElement("description")]publicstringDescription{get;set;}}classProgram{staticvoidMain(string[]args){varlist=newList{newClass1(){Description="Desc1"},newClass1(){Description="Desc2"}};varserializer=newXmlSerializer(typeof(List),newXmlRootAttribute("root"

c# - BinaryFormatter.ILMerge 后反序列化 "unable to find assembly"

我有一个带有引用dll的C#解决方案(也是具有相同.Net版本的C#)。当我构建解决方案并运行生成的exe时,没有合并exe和引用的dll,一切正常。现在我想将它们合并到一个exe中。我运行ILMerge,一切似乎都正常。我尝试执行exe,它似乎运行良好,直到它尝试反序列化在引用的dll中定义的对象。using(Streamfstream=newFileStream(file_path,FileMode.Open)){BinaryFormatterbf=newBinaryFormatter();returnbf.Deserialize(fstream)asControlledRuleC

c# - 使用 restsharp 序列化对象并将其传递给 WebApi 而不是序列化列表

我有一个看起来像的View模型。publicclassStoreItemViewModel{publicGuidItemId{get;set;}publicListStoreIds{get;set;}[Required]publicstringDescription{get;set;}//[Required]//[DataMember(IsRequired=true)]publicintItemTypeId{get;set;}}我有一个使用RestSharp的小helper。publicstaticIRestResponseCreate(objectobjectToUpdate,str

c# - WCF 绑定(bind)使用的序列化的性能测试

我有以下对象:publicpartialclassGame{publicboolFinished{get;set;}publicGuidGameGUID{get;set;}publiclongGameID{get;set;}publicboolGameSetup{get;set;}publicNullableMaximumCardsInDeck{get;set;}publicPlayerPlayer{get;set;}publicPlayerPlayer1{get;set;}publicboolPlayer1Connected{get;set;}publicboolPlayer1Env

c# - 使用 DataContractJsonSerializer 将 JSON 反序列化为字典

这个问题在这里已经有了答案:DeserializingaJSONobjecthierarchyintoahierarchyofDictionary(2个答案)关闭4年前。我在响应中收到以下JSON结果:{"result":{"":-41.41,"ABC":0.07,"XYZ":0.00,"Test":0.00}}我已经为反序列化准备了以下类:[DataContract]publicsealedclassRpcResponse{[DataMember(Name="result")]publicList>Result{get;set;}}然而,当我试图用DataContractJsonSe

c# - 使用 XmlSerializer 反序列化随机/未知类型

这个问题在这里已经有了答案:DeserializeXMLToObjectusingDynamic(1个回答)关闭7年前。我正在使用XmlSerializer与服务通信。这不是常规的SOAP服务,它有自己的XML对象类型。例如,我可能会要求对象,但它可能返回.因此,换句话说,我必须处理随机的XML文档类型。但是,我知道我必须处理哪些类型。我正在尝试做的是找到一种通用方法来序列化/反序列化这些文档。问题是XmlSerializer需要在创建阶段知道类型。这些没有封装在公共(public)根元素中,因此创建一个基类并使用[XmlInclude]属性在这种情况下不起作用:[XmlInclude