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. I'm thinking the issue is with the JSON.
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. How can I get on the right track here?