我有一个来自 json 的 nsdictionary,它响应:
({
email = "something@gmail.com";
name = "User1";
},
{
email = "something2@gmail.com";
name = "user2";
})
这是我在 de .m 文件中的代码:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
int errorCode = httpResponse.statusCode;
NSString *fileMIMEType = [[httpResponse MIMEType] lowercaseString];
NSLog(@"response is %d, %@", errorCode, fileMIMEType);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
//NSLog(@"data is %@", data);
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//NSLog(@"string is %@", myString);
NSError *e = nil;
usersDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&e];
NSLog(@"dictionary is %@", usersDictionary);
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NombreUsuario = [[NSMutableArray alloc] initWithCapacity:[usersDictionary count]];
}
我用它来返回部分中的行数:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [usersDictionary count];
}
但是我不知道如何将这对数据 email,name 放入 tableview 中,其中每个单元格都必须显示名称的主标签和电子邮件的副标题。
提前致谢。