2012-10-17 31 views

回答

4

您還需要在字典中循環,爲了做到這一點,您可以使用Foreach來迭代tempDic

foreach(Dictionary<string, string> tempDic in rootNode) 
{ 
    foreach(KeyValuePair<string, string> _x in tempDic) 
    { 
     Response.Write(_x.key + "," + _x.value + "<br>"); 
    } 
} 
+0

但數組列表只有12行,有哪行只有一個字典,而使用2個foreach會打印出大約62行數據。 – hkguile

0

你可以使用LINQ第一個獲得所有KeyValuePair s的列表(實際上IEnumerable<KeyValuePair<string, string>>):

var pairs = rootNode.OfType<Dictionary<string, string>>() 
        .SelectMany(d => d.AsEnumerable()); 
foreach (KeyValuePair<string, string> tempPair in pairs) 
{ 
    Response.Write(tempPair.Key + "," + tempPair.Value + "<br>"); 
} 

所以,這將是足夠的做只有一個foreach循環。另一個將由LINQ爲您完成。

相關問題