Lots has been written about this topic and I seem to be following exactly as the documentation indicates, but something is clearly a bit off. After working on this all day, I'm thinking the issue is with the JSON, but maybe you guys can help me sort it out differently.
Trying to take a JSON response, which looks like this:
JSON RESPONSE FROM NSLOG:
{
0 = "{\"name\":\"Dinner\", \"date\":\"2014-05-23\", \"time\":\"7:00PM\"}";
}
Convert it to an NSArray, like this:
NSString *url = @"http://localhost:8888/rendezvous/index.php/get_events";
dispatch_async(kBgQueue, ^{
NSURL *request=[NSURL URLWithString:url];
NSData* data = [NSData dataWithContentsOfURL: request];
dispatch_sync(dispatch_get_main_queue(), ^{
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&error];
_events = [[json valueForKey:@"0"] valueForKey:@"name"];
And output it to a tableViewCell like so:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"EventCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = [_events objectAtIndex:indexPath.row];
return cell;
}
Presently, I'm getting null for the events array, presumably due to unfamiliarity on how to work with and access this bizarre-looking JSON response. Can anyone help me get on the right track here?
P.S. I've tried to be thorough but brief here, so please let me know if you'd like me to provide anything else that may be helpful.
Thanks!