我不知道如何從這個JSON數據中檢索特定的數據並在tableview中插入。如何在iOS的表格視圖中檢索json數據
{
"error": "ok",
"data": [{
"facebook_id": "1068644546541665",
"user_id": "95590e92-6c74-44d1-9e5c-5a10c6341ba3",
"name": "Sunil",
"trackingallowed": 1,
"trackingpermission": 1
}, {
"facebook_id": "10311905002886663",
"user_id": "95ab5fc0-9c6d-4e3e-9cb2-bfa4d53e640f",
"name": "Saravanan",
"trackingallowed": 1,
"trackingpermission": 1
}, {
"facebook_id": "998936463528828",
"user_id": "cd6e3c89-bc2d-45a9-8436-9603e1b4724b",
"name": "Suresh",
"trackingallowed": 1,
"trackingpermission": 1
}]
}
獲取通過列表數組中的值。
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[friendsconnection_data appendData:data];
NSError *localerror;
NSDictionary *parsedobject =[NSJSONSerialization JSONObjectWithData:data options:0 error:&localerror];
NSLog(@"parsedobject1 %@",parsedobject);
ListArray = [parsedobject valueForKey:@"data"];
NSLog(@"rrresults1 %lu",(unsigned long)ListArray.count);
NSLog(@"results1 %@",ListArray);
}
我得到EXC_BAD_ACCESS。我需要知道如何從JSON獲取特定數據。例如我只想得到facebookid
和name
。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self FriendsData];
static NSString *TableIdentifier [email protected]"tableitem";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:TableIdentifier];
if(cell == nil)
{
cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifier];
}
cell.textLabel.text = [[ListArray objectAtIndex:indexPath.row]objectForKey:@"name"];
tableView.rowHeight = 300;
return cell;
}
是什麼的cellForRowAtIndexPath該功能的工作高度? – Jaimish
哪條線路導致崩潰?什麼是'FriendsData'方法,爲什麼從'cellForRowAtIndexPath'調用? – rmaddy
不相關,但爲什麼每次調用cellForRowAtIndexPath時都要設置表視圖的'rowHeight'? – rmaddy