2015-01-13 27 views
-1

您好,我在iOS開發中更新鮮。 下面是我收到的錯誤:語法錯誤:方法調用的參數過多,預​​計爲1,有2個

generate syntax error. error like as "Too many arguments to method call, expected 1, have 2"

for (int i=1; arrParseRespnse.count; i++) 
{ 
    [arruserName addObject:[[arrParseRespnse objectForKey:@"%@",i]objectForKey:@"userName"]];    
} 

error:Too many arguments to method call, expected 1, have 2

感謝。

Screenshot

+0

什麼是'[arrParseRespnse objectForKey:@「%@」,i]'應該是? – rmaddy

+0

仍然會產生錯誤:我想從json獲取值,代碼是:{ 1 = {0} {0} {0} {0} currentHeader = 0; emailid =「[email protected]」; password = password; userId = 11; userName = defaultUser; }; 2 = {current_eader = 0; emailid =「[email protected]」; password = sam; userId = 12; userName = sam; }; 3 = {current_eader = 0; emailid =「[email protected]」; password = amit; userId = 13; userName = amit; }; } – Bhavdip

回答

0

你寫

objectForKey:@"%@",i 

是不正確的部分。這種方法只需要一個參數,但你給它2

+0

從json獲得值:{ 1 = {0} {0} {0} currentHeader = 0; emailid =「[email protected]」; password = password; userId = 11; userName = defaultUser; }; 2 = {current_eader = 0; emailid =「[email protected]」; password = sam; userId = 12; userName = sam; }; 3 = {current_eader = 0; emailid =「[email protected]」; password = amit; userId = 13; userName = amit; }; } – Bhavdip

1

你的代碼應該是:

for (NSInteger i = 1; i <= arrParseRespnse.count; i++) { 
    NSString *key = [NSString stringWithFormat:@"%ld", (long)i]; 
    [arruserName addObject:arrParseRespnse[key][@"userName"]]; 
} 

注意現代語法和i你的關鍵的正常建設。

+0

謝謝..解決了它rmaddy – Bhavdip

+0

很高興我能幫到你。儘可能接受答案,隨時關閉問題。 – rmaddy

相關問題