使用RestSharp反序列化XML-将对象嵌套到SQLite数据库中

问题描述

我正在从XML格式的API中提取数据并将其插入sqlite数据库中。我已经从https://xmltocsharp.azurewebsites.net/网站上进行了课程。

我的问题是,当表具有嵌套对象时。在这种情况下,它将插入到数据库中的“ Manager”一列下,然后将数据以看起来像JSON类型的格式插入数据库中。 {UUID:b878ggc5-bdg-49g-9215-29gg578a396,Name:David Becker} 有些对象比其他对象复杂,但是大多数对象只能作为UUID存储,因为可以从另一个表中检索数据,但是我无法弄清楚如何仅在新列下而不是整个对象下存储数据

这些类看起来像这样:

[XmlRoot(ElementName = "Staff")]
public class TimeStaff
{
    [XmlElement(ElementName = "UUID")]
    public string UUID { get; set; }
    [XmlIgnore]
    public string Name { get; set; }
}

[XmlRoot(ElementName = "Time")]
public class Time
{
    [XmlElement(ElementName = "UUID")]
    public string UUID { get; set; }
    [XmlElement(ElementName = "Staff")]
    public Staff Staff { get; set; }
    [XmlElement(ElementName = "Date")]
    public string Date { get; set; }
    [XmlElement(ElementName = "Minutes")]
    public string Minutes { get; set; }
    [XmlElement(ElementName = "Note")]
    public string Note { get; set; }
    [XmlElement(ElementName = "Billable")]
    public string Billable { get; set; }
    [XmlElement(ElementName = "Start")]
    public string Start { get; set; }
    [XmlElement(ElementName = "End")]
    public string End { get; set; }
    [XmlElement(ElementName = "InvoiceTaskUUID")]
    public string InvoiceTaskUUID { get; set; }
}

在上述情况下,我很乐意仅将Staff对象另存为“ StaffUUID”列,而该字段仅具有UUID属性

我的另一个问题是RestSharp似乎不适用于上面列出的属性

我的数据库插入内容如下:

var costList = APIConnector.GetobjectList<Cost>(costListAPI,configuration["TenantId"],configuration["BearerToken"]);

            db.DropAndCreateTable<Cost>();

            foreach (var item in costList)
            {
                db.Insert(item);
            }

使用方法

public static List<T> GetobjectList<T>(string apiEndpoint,string tenantId,string bearerToken)
        {
            var apiResult = APIConnectionHelper(apiEndpoint,tenantId,bearerToken);

            var data = new XmlAttributeDeserializer();

            if (apiResult.Result.IsSuccessful)
            {
                return data.Deserialize<List<T>>(apiResult.Result);
            }

            else
            {
                Console.WriteLine("Server response error: " + apiResult.Result.Content);
                return null;
            }

        }

在这里有点不了解。在这种情况下,有人可以为我指出使用Ormlite进行更复杂的数据库插入的正确方向。还有RestSharp的一些反序列化属性,我一生都找不到。 我尝试寻找解决方案,也许我的方向不对,所以很抱歉,如果已解决此问题,但我找不到。

非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)