我試圖根據更新時間(保存在數據庫中)下載基於服務器的文件(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
}
}
}
是的。糾正。 –