Hi I have a method that gets a list of district and i need to display the district list in a pickerview. Here is the response that I am receiving:
[{"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"]
Here's what I have so far: (this called in textFieldDidBeginEditing)
else if(textField == _districtTextField)
{
pickerComponentsArray = districtArray;
[pickerView reloadAllComponents];
[pickerView selectRow:0 inComponent:0 animated:YES];
[textField setText:[districtArray objectAtIndex:0]];
[textField setInputView:pickerViewContainer];
}
when my code reaches [pickerView selectRow:0 inComponenet:0 animated:YES]; my app crashes. this is the error that i am getting:
[__NSCFDictionary length]: unrecognized selector sent to instance 0x1744784c0 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary length]: unrecognized selector sent to instance 0x1744784c0'
I am suspecting this is because of the nested array. How can I parse the jsonString that I am receiving. I've tried doing this:
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];
I'm still receiving the same error. Is there a way to parse the json response? Can I delete the values(Caloocan, Las Pinas, etc..) under @"NCR" key? When the calues are deleted, is "NCR" key still part of the original array (NCR, Abra, etc..)? Thanks!