嗨我有一個方法,獲取區的列表,我需要在pickerview中顯示區列表。 下面是我收到的迴應:如何通過值(非鍵)刪除數組中的項目
[{"NCR":[ "Caloocan", "Las Piñas", "Makati", "Malabon ", "Mandaluyong", "Manila", "Marikina", "Muntinlupa", "Navotas", "Parañaque", "Pasay", "Pasig", "Quezon", "San Juan", "Taguig", "Valenzuela", "Pateros"]}, "Abra", "Agusan del Norte", "Agusan del Sur", "Aklan", "Albay", "Antique", "Apayao", "Aurora", "Basilan", "Bataan", "Batanes", "Batangas", "Benguet", "Biliran", "Bohol", "Bukidnon", "Bulacan", "Cagayan", "Camarines Norte", "Camarines Sur", "Camiguin", "Capiz", "Catanduanes", "Cavite", "Cebu", "Compostela Valley", "Cotabato", "Davao del Norte", "Davao del Sur", "Davao Oriental", "Dinagat Islands", "Eastern Samar", "Guimaras", "Ifugao", "Ilocos Norte", "Ilocos Sur", "Iloilo", "Isabela", "Kalinga", "La Union", "Laguna", "Lanao del Norte", "Lanao del Sur", "Leyte", "Maguindanao", "Marinduque", "Masbate", "Metro Manila", "Misamis Occidental", "Misamis Oriental", "Mountain Province", "Negros Occidental", "Negros Oriental", "Northern Samar", "Nueva Ecija", "Nueva Vizcaya", "Occidental Mindoro", "Oriental Mindoro", "Palawan", "Pampanga", "Pangasinan", "Quezon", "Quirino"]
這是我到目前爲止有:(這稱爲textFieldDidBeginEditing)
else if(textField == _districtTextField)
{
pickerComponentsArray = districtArray;
[pickerView reloadAllComponents];
[pickerView selectRow:0 inComponent:0 animated:YES];
[textField setText:[districtArray objectAtIndex:0]];
[textField setInputView:pickerViewContainer];
}
,當我的代碼已達到[pickerView selectRow:0 inComponenet:0動畫:是];我的應用程序崩潰。這是我收到的錯誤:
[__NSCFDictionary長度]:無法識別的選擇發送到實例0x1744784c0 終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因:「 - [__ NSCFDictionary長度]:無法識別的選擇發送到實例0x1744784c0'
我懷疑這是因爲嵌套數組。我如何解析我收到的jsonString。 我試着這樣做:
pickerComponentsArray = districtArray;
NSMutableArray* mutableArray = [pickerComponentsArray mutableCopy];
for(int i=0;i<mutableArray.count;i++){
NSMutableDictionary *outerDictionary = [mutableArray objectAtIndex:i];
for(NSString *key in outerDictionary.allKeys){
NSMutableDictionary *innerDictionary = [[outerDictionary objectForKey:key] mutableCopy];
[innerDictionary removeObjectForKey:key];
}
[pickerView reloadAllComponents];
[pickerView selectRow:0 inComponent:0 animated:YES];
[textField setText:[districtArray objectAtIndex:0]];
[textField setInputView:pickerViewContainer];
我仍然收到了同樣的錯誤。有沒有辦法解析JSON響應?我可以刪除@「NCR」鍵下的值(Caloocan,Las Pinas等)嗎?當calues被刪除時,「NCR」鍵仍然是原始數組的一部分(NCR,Abra等)。 謝謝!
將數組的所有鍵與它們的值進行比較並刪除鍵值對.. – iHart
http://stackoverflow.com/questions/111866/best-way-to-remove-from-nsmutablearray-while-iterating勾選此項回答 – vijeesh
你的回答是「陣列**的字典數組」。 – Sujay