Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing JSON value on UIPickerview xcode
    primarykey
    data
    text
    <p>I have a pickerview with which I would want to display values using JSON parsing. I am aware some questions on the site already tackle parsing and pickerview but mine is slightly different in regards to the structure of my json file. Here's a sample of the json file.</p> <pre><code>[ { "model":"juice", "id" : [ { "version": "version01" }, { "version": "version02" } ] }, { "model":"cream", "id" : [ { "version": "cream01" }, { "version": "cream02" } ] } ] </code></pre> <p>and my .m file</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSURL * serverhost = [NSURL URLWithString:@"http://my.json"]; NSError *error; NSData * Data = [NSData dataWithContentsOfURL: serverhost]; self.modelsArray= [NSJSONSerialization JSONObjectWithData:Data options:NSJSONReadingAllowFragments error:&amp;error]; NSLog(@"%@", modelsArray); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 2; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { if (component == departments) return [self.modelsArray count]; return [self.versionsArray count]; } #pragma mark Picker Delegate Methods - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { if (component == departments) return [[self.modelsArray objectAtIndex:row]objectForKey:@"model"]; return [[[self.versionsArray objectAtIndex:row]objectForKey:@"model"]objectForKey:@"version"]; } -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component { if (component == departments) { NSString * selectedRow = [[self.modelsArray objectAtIndex: row] valueForKey:@"version"]; NSArray * array = [sybreDepts objectForKey:selectedRow]; self. } } @end </code></pre> <p>Basically when I select a model i.e juice or cream on the first column the second column should display its contents with key being 'versions' thus when juice is selected "version01" and "version02" should be displayed on the second column.</p> <p>In regards to the line <code>return [[[self.versionsArray objectAtIndex:row]objectForKey:@"model"]objectForKey:@"version"];</code> I don't believe it was executed correctly as I get an error</p> <pre><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0xa18c450' . Any suggestions ? Thanks </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload