2012-11-22 23 views
1

的字典中的數組中獲得價值從我的iOS應用程序調用Web服務,它返回字典詞典,, 這樣如何從字典

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>1</key> 
    <dict> 
     <key>Business classification</key> 
     <string>a:2:{i:0;s:19:"Broker - Securities";i:1;s:18:"Financial Services";}</string> 
     <key>Cell phone</key> 
     <string>(2201258886</string> 
     <key>Company position</key> 
     <string>First Vice President - Wealth Management, CFP?</string> 
     <key>Country</key> 
     <string>UNITED STATES of AMERICA</string> 
     <key>Email</key> 
     <string>[email protected]</string> 
     <key>Full name</key> 
     <string>llndrees</string> 
     <key>Office phone</key> 
     <string>(707) 571-5761</string> 
     <key>Rkkkty/name</key> 
     <string>Santkkka Roskka</string> 
     <key>State</key> 
     <string>Cakklifornia</string> 
     <key>user_id</key> 
     <string>1</string> 
    </dict> 
    <key>10</key> 
    <dict> 
     <key>Business classification</key> 
     <string>a:1:{i:0;s:16:"Business advisor";}</string> 
     <key>Cell phone</key> 
     <string>415-491-4102</string> 
     <key>Company position</key> 
     <string>Business Adviser</string> 
     <key>Country</key> 
     <string>UNITED STATES of AMERICA</string> 
     <key>Email</key> 
     <string>[email protected]</string> 
     <key>Full name</key> 
     <string>Biolas</string> 
     <key>Office phone</key> 
     <string>415+656165402</string> 
     <key>Rotuhuhame</key> 
     <string>Tiburon</string> 
     <key>State</key> 
     <string>Caliggggfornia</string> 
     <key>user_id</key> 
     <string>13</string> 
    </dict> 

現在我需要得到所有電子郵件一個數組我怎麼做這個 我想這

NSDictionary * Usernames = [[NSDictionary alloc]initWithContentsOfFile:strDocDirPath]; 


      NSLog(@"%@",[Usernames valueForKey:@"Email"]); 

但其返回nil ,,任何人可以幫我請

回答

0

它應該是一個循序漸進的PR ocess, 嘗試這樣

NSLog(@"%@",[[Usernames valueForKey:@"first key"] valueForKey:@"second key"]); 
0

使用字典的這個功能來枚舉和收到的電子郵件的所有值,並將其存儲陣列。

  • (無效)enumerateKeysAndObjectsUsingBlock:(無效(^)(ID密鑰,ID OBJ,BOOL *停止))塊
1

你應該嘗試類似如下:

NSDictionary * Usernames = [[NSDictionary alloc]initWithContentsOfFile:strDocDirPath]; 
    for (NSDictionary *item in Usernames) 
    { 
     NSLog(@"%@",[item valueForKey:@"Email"]); 
    }