Afnetworking Usage Summary (Usage +json parsing)

Source: Internet
Author: User
Tags vcard

Local cache issues for «afnetworking picturesGet Application Bundle seed ID in IOS»Afnetworking Usage Summary (Usage +json parsing)

from:http://www.coneboy.com/?p=716

These days in the review page when the GET request to add more than 2 characters will appear badurl hint, breakpoint debugging found to be a lot of Chinese characters, so in the URL before using the first transcoding into UTF-8 can
Here, by the way, is the usual way to use afnetworking.

At the moment, I just use
#import "AFHTTPClient.h";
#import "AFHTTPRequestOperation.h"
These two classes

Initiate a request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
NSString *urltmp = @ "http://www.coneboy.com";
NSString *URLTMP1 = [urltmp stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; Transcode to UTF-8 otherwise error may occur
Urltmp = URLTMP1;
Nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:urltmp];
Afhttprequestoperation *operation = [[Afhttprequestoperation alloc] initwithrequest:request];
[Operation setcompletionblockwithsuccess:^ (afhttprequestoperation *operation, id responseobject) {
NSLog (@ "Success:%@", operation.responsestring);

NSString *requesttmp = [NSString stringWithString:operation.responseString];
NSData *resdata = [[NSData alloc] initwithdata:[requesttmp datausingencoding:nsutf8stringencoding]];
The system comes with JSON parsing
Nsdictionary *resultdic = [nsjsonserialization jsonobjectwithdata:resdata options:nsjsonreadingmutableleaves Error: NIL];

} failure:^ (Afhttprequestoperation *operation, Nserror *error) {
NSLog (@ "Failure:%@", error);
[Svprogresshud dismisswitherror:@ "commit failed, please retry"];
}];
[Operation start];
}

afnetworking Download Image
afnetworking download image is asynchronous and can be cached inside the cache very good does not block the main thread. Used to all said! And it's easy to use!
#import "Uiimageview+afnetworking.h"

1 [ImageView Setimagewithurl:[nsurl Urlwithstring:url];

Afnetworking Usage Summary (Usage +json parsing)

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.