1.根据提供的网址首先将json文件下载下来
(json文件中存储的是key-value,其中value对应的可能是一个数组)
#import "SBJson.h"
#import "UIImageView+WebCache.h"
NSString *urlstr = @"http://192.168.88.8/sns/my/ user_list.php?page=1number=500";
//把字符串变成合法的请求
NSURL *url = [NSURL URLWithString:urlstr];
NSError *error = nil;
NSString *data = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
if(error)
{
exit(-1);
}
NSDictionary *friendData = [data JSONValue];
NSArray *frendArray = [friendData objectForKey:@"users"];
friendsAfterJson = [[NSMutableArray alloc] initWithCapacity:0];
for (NSDictionary *oneDict in friendArray) {
UserItem *oneGuy = [[UserItem alloc] init];
oneGuy.userName = [oneDict objectForKey:@"username"];
oneGuy.realName = [oneDict objectForKey:@"realname"];
oneGuy.imageUrl = [NSString stringWithFormat:
@"http://192.168.88.8/sns%@",[oneDict objectForKey:@"headimage"]];
[friendsAfterJson addObject:oneGuy];
}
//文字信息以保存,下载图片(使用SDWebImage中的setImageWithURL:)方法
- (UITableViewCell *)tabelView …..
{
UserItem *oneUser = [friendsAfterJson objectAtIndex:indexPath.row];
[cell.headView setImageWithURL:[NSURL URLWithString:oneUser.imageUrl]]
}