Note on the use of NSJSONSerialization in iOS, and the use of block in ios
This is the first Json parsing method. Because it is easy to use and has a high resolution efficiency, NSJSONSerialization is the best choice for Json data parsing. Below is a simple attachment of my code ~
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 );
Now the img array stores my image URLs ~~ Easy to use ~ Just a few lines of code