2011-04-09 67 views
1

我有以下代碼:的NSDictionary到顯示每個項目

for (int i = 1; i<=count; i++) { 

    NSString *j = [[NSString alloc] initWithFormat:@"%d",i ]; 

    NSArray *fields = [[NSArray alloc] initWithObjects: 
         @"name",nil]; 
    //@"title",@"mobile",@"email",@"website" 
    [requestExecute setMethod:@"execute" withObjects:[NSArray arrayWithObjects: 
                  @"testdb",userid,@"admin",@"res.partner.contact",@"read",j,fields,nil]]; 
    NSDictionary *records=[self executeXMLRPCRequest:requestExecute]; 

NSLog(@"\nKey : %@ value : \n",records); 

輸出類似於

2011-04-09 12:34:32.431的ERP [1571:207]

( 
     { 
     email = "[email protected]"; 
     id = 1; 
     mobile = 12345; 
     name = Mortier; 
     title = "Ms."; 
     website = "www.benoit.com"; 
    } 
) 
2011-04-09 12:34:32.515 Erp[1571:207] ( 
     { 
     email = "[email protected]"; 
     id = 2; 
     mobile = 23455; 
     name = Jacot; 
     title = "M."; 
     website = "www.laurent.com"; 
    } 
) 
2011-04-09 12:34:32.599 Erp[1571:207] ( 
     { 
     email = "[email protected]"; 
     id = 3; 
     mobile = 34567; 
     name = Passot; 
     title = "M."; 
     website = "www.thomas.com"; 
    } 
) 
2011-04-09 12:34:32.683 Erp[1571:207] ( 
     { 
     email = "[email protected]"; 
     id = 4; 
     mobile = 45678; 
     name = Lacarte; 
     title = Mss; 
     website = "www.etienne.com"; 
    } 
) 
2011-04-09 12:34:32.767 Erp[1571:207] ( 
     { 
     email = "[email protected]"; 
     id = 5; 
     mobile = 56789; 
     name = Tang; 
     title = Mss; 
     website = "www.chow.com"; 
    } 
) 
2011-04-09 12:34:32.851 Erp[1571:207] ( 
     { 
     email = "[email protected]"; 
     id = 6; 
     mobile = 1237091; 
     name = Wong; 
     title = "M."; 
     website = "www.hudson.com"; 
    } 
) 

這會逐一打印每條記錄。現在我想逐一記錄這個記錄中的每個字段。任何幫助,將不勝感激。

回答

0

我不確定requestExecute會做什麼,但是如果您想循環遍歷NSDictionary中的所有值,您可以使用[records allKeys],它將返回字典中所有鍵的NSArray。

+0

的requestExecute是執行XMLPassing。從開放的erp系統收集數據的功能。 – alanvabraham 2011-04-09 05:38:00

3

的Objective-C 2.0支持很方便快速列舉語法收藏...

for(NSString *aKey in records){ 
    NSLog(@"%@", [[records valueForKey:aKey] description]); 
} 
+0

[__NSCFDictionary length]:無法識別的選擇器發送到實例0x4b4e8f0 2011-04-09 11:11:08.221 Erp [985:207] ***終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [__ NSCFDictionary length] :無法識別的選擇器發送到實例0x4b4e8f0' 當您執行您指定的操作時,我收到了這樣的錯誤。 – alanvabraham 2011-04-09 05:44:01

+0

我更新了代碼提取,我錯過了在日誌語句中的字符串:) – mmccomb 2011-04-09 05:53:07

相關問題