我有我的主要程序类的列表获取值调用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