Note on the use of NSJSONSerialization in iOS, and the use of block in ios

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.