-3
我正在使用.First()
進行API調用並出現sequence contains no elements
的錯誤,但使用.FirstOrDefault()
時出現同樣的錯誤。該語法應如何更改以避免出現此錯誤?序列不包含C#中的元素錯誤
public class Root
{
public List<AI> AI { get; set; }
}
public class AI
{
public List<Dictionary<string, string>> AddressInfo { get; set; }
}
public class Main[]
{
var response = syncClient.DownloadString(url);
var returnData = JsonConvert.DeserializeObject<Root[]>(response);
foreach (Root ro in returnData)
{
foreach (AI info in ro.AI)
{
string address = info.AddressInfo.First()["Address1"]);
string address2 = info.AddressInfo.First()["Address2"]);
string city = info.AddressInfo.First()["City"]);
string state = info.AddressInfo.First()["State"]);
string zip = info.AddressInfo.First()["Zip"]);
Conesole.ReadLine();
}
}
}
我不得不刪除收盤括號但除此之外,它的工作太棒了!謝謝你的回覆 – IcyPopTarts