コード例 #1
0
        protected static DirectoryData DeserializeDirectoryXml(String dir, XElement root)
        {
            DirectoryData dd = new DirectoryData(dir);

            foreach (XElement elem in root.Elements())
            {
                XAttribute iname = elem.Attribute("item");
                string     name  = iname == null ? elem.Name.LocalName : iname.Value;

                if (elem.Attribute("type").Value == "object")
                {
                    dd.directories.Add(DeserializeDirectoryXml(name, elem));
                }
                else if (elem.Attribute("type").Value == "array")
                {
                    dd.files.Add(DeserializeFileXml(name, elem));
                }
                else
                {
                    throw new ApiException("Parser error. API respond is malformed.");
                }
            }

            return(dd);
        }
コード例 #2
0
        protected static DirectoryData DeserializeDirectoryXml(String dir, XElement root)
        {
            DirectoryData dd = new DirectoryData(dir);

            foreach (XElement elem in root.Elements())
            {
                XAttribute iname = elem.Attribute("item");
                string name = iname == null ? elem.Name.LocalName : iname.Value;

                if (elem.Attribute("type").Value == "object")
                {
                    dd.directories.Add(DeserializeDirectoryXml(name, elem));
                }
                else if (elem.Attribute("type").Value == "array")
                {
                    dd.files.Add(DeserializeFileXml(name, elem));
                }
                else
                {
                    throw new ApiException("Parser error. API respond is malformed.");
                }
            }

            return dd;
        }
コード例 #3
0
        public static DirectoryData DeserializeJson(string json)
        {
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
            {
                XmlReader reader = JsonReaderWriterFactory.CreateJsonReader(ms, XmlDictionaryReaderQuotas.Max);
                XElement  root   = XElement.Load(reader);

                DirectoryData tret = DeserializeDirectoryXml("/", root);
                return(tret);
            }
        }