初接觸的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了~~簡單吧~就幾行代碼