我试图根据更新时间(保存在数据库中)下载基于服务器的文件(PDF)。在下载之前,我想将它们与本地机器上现有的文件列表进行比较。问题是比较对象字段给出错误的输出。比较两个对象列表中的<Items>在C#UWP
这两个文件都是基于json的文件,在下面给出的“ITEMS”对象中解析。我正在使用Visual Studio 2015与C#。后端是Laravel REST。
class Items
{
public int id { get; set; }
public string branch { get; set; }
public string item { get; set; }
public string link { get; set; }
public int active { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
}
这是怎么了解析服务器和本地列表(包括JSON):
for (int i = 0; i < obj.Count; i++)
{
JObject row = JObject.Parse(obj[i].ToString());
Items newItem = new Items();
newItem.id = int.Parse(row["id"].ToString());
newItem.branch = row["branch"].ToString();
newItem.item = row["item"].ToString();
newItem.link = row["link"].ToString();
newItem.created_at = row["created_at"].ToString();
newItem.updated_at = row["updated_at"].ToString();
files.Add(newItem);
}
我使用foreach循环检查的updated_at字段等于或不
// Compare files
foreach (Items item in files)
{
foreach(Items it in filesToDownload)
{
if (!it.updated_at.Equals(item.updated_at))
{
//Download the file
//Create a new list of files to download
}
}
}
是的。纠正。 –