我有我的主要程序類的列表獲取值調用StronyElementuStrukt
程序C#不能從對象
List<object> monthlyPages = new List<object>();
monthlyPages = StronyElementuStrukt(loginGuid, "8B35134E10A8432DB1A8C06A58427988");
下面是該過程 - 即建立XML節點列表,並返回到主程序的方法類:
public static List<object> StronyElementuStrukt(string LoginGUID, string LinkGUID)
{
List<object> listPages = new List<object>();
XmlDocument document = new XmlDocument(); // tworzenie nowego obiektu - dokument xml z odpowiedzia serwera
document.LoadXml(response.Result); //wczytywanie xmla z odpowiedzia serwera do obiektu
XmlNode pageNode = document.SelectSingleNode("/IODATA/PAGES/PAGE"); //deklaracja noda xmlowego
if (pageNode != null) //jeżeli PAGE node istnieje
{
XmlNodeList nodeList = document.SelectNodes("//PAGE");
foreach (XmlNode node in nodeList)
{
listPages.Add(node);
}
return listPages;
}
}
在主程序類我需要拿起XML id
屬性的值,我試圖做這樣的:
foreach (object monthlyPage in monthlyPages)
{
Console.WriteLine(monthlyPage.Attributes["id"].Value);
}
的問題是,當我試圖讓id
我得到以下錯誤:
Error 6 'object' does not contain a definition for 'Attributes' and no extension method 'Attributes' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
你能告訴我如何到達XML在foreach循環屬性,好嗎?請問是否有不清楚的地方。
爲什麼不使用'名單'?此外,在重新分配「StronyElmentStrukt」的結果之前,不需要爲「monthlyPages」分配新的空列表。 –
juharr
輝煌,它的工作原理,我把它從'List