草庐IT

swift-dictionary

全部标签

c# - 将 Dictionary(string, List<string>) 序列化为 xml

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:EasywaytoconvertaDictionarytoxmlandvisaversa我有示例类:publicclassSampleClass{publicDictionary>SampleProperties{get;set;}}我想将这个类序列化为xml。我该怎么做?我想要类似于此示例的输出xml:问候

python - 在 python 中重构这个 dictionary-to-xml 转换器

这真的是一件小事:我有这个将dict对象转换为xml的函数。函数如下:defdictToXml(d):fromxml.sax.saxutilsimportescapedefunicodify(o):ifoisNone:returnu'';returnunicode(o)lines=[]defaddDict(node,offset):forname,valueinnode.iteritems():ifisinstance(value,dict):lines.append(offset+u""%name)addDict(value,offset+u""*4)lines.append(off

xml - 使用 XML 解析 Swift 库时,Playgrounds 崩溃并显示 "unknown error"

我正在开发一个涉及一些XML解析的自定义框架,使用Kanna框架。每当我尝试将我的框架导入playground时,playground就会崩溃并出现以下错误:Playgroundexecutionfailed:expressionfailedtoparse,unknownerror*thread#1:tid=0x4e9448,0x00000001074bf360com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground,queue='com.apple.main-thread',stopreason=breakpoint1.1*

c# - LINQ to Dictionary - 使用 XML

我已经问过一个类似的问题,当然,这个问题是不同的,我试过了。我尝试使用Linq读取XML数据并解决了这个问题,但是,我需要选择多个值并将它们存储到字典中。我已经尝试过(评论是我的尝试)但我无法弄清楚并收到如下错误:System.NullReferenceException:Objectreferencenotsettoaninstanceofanobjectatdsdsdsds.MainClass+c__AnonStorey0.m__0(System.Xml.Linq.XElementdatanum)[0x00000]in/Users/p/Projects/dsdsdsds/dsdsd

c# - 如何将 XML 文件读取到 Dictionary<String,List<String>> 中,空字符串为 null 元素

我有一个像这样的xml文件:和像这样的字典:Dictionary>MyDict=newDictioanary>();我正在读取XML文件到MyDict就像:XDocumentXDoc=XDocument.Load(Application.StartupPath+@"\foo.xml");MyDict=XDoc.Descendants("RowDetails").ToDictionary(X=>X.Attribute("RowName").Value,X=>X.Descendants("ColumnDetails").Select(Y=>Y.Attribute("ColumnName")

c# - 如何使用 WebAPI 返回 Dictionary<complexType,int>

我提供了一个以这种方式完成的WebApi2端点:我的Controller很简单:publicIDictionaryGetMyClasses(stringid){Dictionarysample=newDictionary();sample.Add(newMyClasses(){Property1="aaa",Property2=5,Property3=8},10);returnsample;}MyClass的结构是:publicclassMyClass{stringProperty1{get;set;}intProperty2{get;set;}intProperty3{get;set

c# - 将 XML 反序列化为 Dictionary<string, string>

我有一些XML;JamesJohnetc..name1、name2等可以是任何东西,我希望能够将此xml理想地放入字典中,这是否可能使用内置的.net序列化?谢谢,詹姆斯。编辑:理想情况下我不想使用linq。是否可以将整个元素数组序列化为字符串?所以我最终会得到一个包含所有子元素标签和数据的字符串对象“Data”? 最佳答案 不,但是您可以使用Linq-to-Xml来这样做:XDocument.Load([filepath,stream,whatever]).Descendants("data").Descendants().ToD

c# - 如何接受 'dictionary' 数据作为自定义 .NET 属性参数?

我最近发现.NET属性只能包含基本类型、字符串、枚举、对象和这些类型的单参数数组,如讨论的那样here.我需要接受IDictionary通过.NET属性,但显然我不能使用IDictionary由于上述原因。因此,我在这里寻找可以在这些准则范围内工作的替代方案。//Iwanttodothis,butcan'tbecauseoftheCLRlimitation[MyAttribute(Attributes=newDictionary{{"visibility","Condition1"},{"myAttribute","some-value"}})]我想到的两个可能的选择是使用XML或JS

c# - 如何将 Dictionary<string, object> 序列化/反序列化为 XML

我正在尝试为我的应用程序编写一个保存例程,其中应用程序的多个部分将项目添加到字典,然后保存功能将它们写入XML文件。open例程需要读取这些文件并重新填充字典,然后我可以将这些对象放回我的应用程序中。我正在为我现在拥有的例程的反序列化而苦苦挣扎。我的保存流程如下XmlDocumentxmlDoc=newXmlDocument();//WritedowntheXMLdeclarationXmlDeclarationxmlDeclaration=xmlDoc.CreateXmlDeclaration("1.0","utf-8",null);//CreatetherootelementXml

c# - 以任何形式(Json、xml 等)序列化 Dictionary<String、Dictionary<String、String>>

将Dictionary>序列化到可以存储的程度,之后反序列化。我进行了大量谷歌搜索,但找不到与.NET4.5完全兼容的类或函数。 最佳答案 开箱即用JavaScriptSerializer应该能应付你的字典。它也应该提供非常紧凑的输出。varsource=newDictionary>{{"one",newDictionary{{"a","1a"},{"b","1b"}}},{"two",newDictionary{{"a","2a"},{"b","2b"}}}};varserializer=newJavaScriptSerializ