初接触的Json解析就是这个,因为觉得简单好用,解析效率还高,所以要进行Json数据解析,NSJSONSerialization真的是不二之选,下面简单的附上我的代码吧~
NSError *error;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.122:8080/app/common/focus/4"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSArray *imgarr = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"%@",imgarr);
img = [[NSMutableArray alloc]init];
for (int i = 0; i<[imgarr count]; i++) {
NSDictionary *imgDic = [imgarr objectAtIndex:i];
NSString *imgstr = (NSString*)[imgDic objectForKey:@"imgsrc"];
NSString *port = @"http://192.168.1.122:8080";//
NSString *imgstr1 = [port stringByAppendingString:imgstr];
[img addObject:imgstr1];
}
NSLog(@"%@",img);
现在img数组里的存放的就是我的图片url了~~简单吧~就几行代码