tableview 中的输出应该在每一行中,我在一行中得到整个响应,其余行是空白的。所以如何在 uitableview 中显示来自服务器的数据的每一行我在 tableview 中得到如下所示的 o/p
aa,bbb,cc……</p>
你好,你好,"",…</p>
o/p 应如下所示
啊
你好
bbb
你好
抄送
“”
这是我的回复 [{"result":[{"request_id":1,"ticket_number":"P_101","email":"xx","user_id":4,"description":"fjdyhsrwgk","status ":"initiated"},{"request_id":2,"ticket_number":"P_102","email":"yyy","user_id":4,"description":"hi","status":"initiated "},{"request_id":3,"ticket_number":"P_103","email":"aaa","user_id":4,"description":"hii","status":"initiated"},{ "request_id":4,"ticket_number":"P_104","email":"bbb","user_id":4,"description":"aa..","status":“发起”}]}]
如何在结果键中获取对象数组
下面是代码
listOfCustomers = [[NSMutableArray alloc]init];
str= [[NSUserDefaults standardUserDefaults] valueForKey:@"user_id"];
NSString *strJson=[NSString stringWithFormat:@"userId=%@",str];
NSString *strlength=[NSString stringWithFormat:@"%d",[strJson length]];
NSURL *url=[NSURL URLWithString:@"url"];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
[request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
[request addValue:strlength forHTTPHeaderField:@"Content-Length"];
NSData *requestData=[strJson dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:requestData];
[request setHTTPMethod:@"POST"];
NSError *err;
NSData *responseData=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&err];
NSString *strResponse=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"response is %@",strResponse);
dict1=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&err];
NSArray *results = [dict1 valueForKey:@"result"];
listOfCustomers = [NSMutableArray array];
for (NSDictionary * oneCustomer in results)
{
// Create a new Customer record
Attributes * newCustomer = [[Attributes alloc] init];
newCustomer.Customer_ID = [oneCustomer valueForKey:@"request_id"];
newCustomer.Company_Name = [oneCustomer valueForKey:@"ticket_number"];
newCustomer.City = [oneCustomer valueForKey:@"email"];
newCustomer.userId = [oneCustomer valueForKey:@"user_id"];
newCustomer.description = [oneCustomer valueForKey:@"description"];
newCustomer.createdTime = [oneCustomer valueForKey:@"createdTime"];
newCustomer.Status = [oneCustomer valueForKey:@"status"];
// Add our new Customer record to our NSMutableArray
[listOfCustomers addObject:newCustomer];
}
[tableVwTotalRequests reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [listOfCustomers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"identifier"];
}
Attributes* cust = [listOfCustomers objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@",cust.Company_Name];
cell.detailTextLabel.text= [NSString stringWithFormat:@"%@",cust.description];
return cell;
}