UI---about synchronizing downloads

Source: Internet
Author: User

{

Nsmutablearray *_datalist;
}

[Self loaddatawithpage:1];

[Self loaddatawithurlconnection];

Remember to initialize the array

_datalist =[nsmutablearray Array];

-(void) loaddatawithurlconnection
{
Create a URL object
Nsurl *url =[nsurl urlwithstring:@ "http://iappfree.candou.com:8080/free/applications/limited//?currency=rmb& Page=1 "];
Create a network Request object
Nsurlrequest *request =[[nsurlrequest Alloc]initwithurl:url cachepolicy:nsurlrequestreturncachedataelseload TIMEOUTINTERVAL:10];
Synchronizing Request data
Nshttpurlresponse *response;
NSData *data =[nsurlconnection sendsynchronousrequest:request returningresponse:&response Error:nil];
NSLog (@ "data=%@", data);
The request data was successful. code=200;
NSLog (@ "code =%li", Response.statuscode);
ID Json =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil];
NSLog (@ "%@", Json);
if ([Json Iskindofclass:[nsdictionary class]]) {
Dictionary method parsing
Nsarray *applications =[json objectforkey:@ "Applications"];
NSLog (@ "%@", applications);
_datalist =[applications Mutablecopy];
}else if ([Json Iskindofclass:[nsarray class]]) {
Array method parsing
}
}
Request data from the network
-(void) Loaddatawithpage: (Nsinteger) PageIndex
{
NSString *urlstring =[nsstring stringwithformat:@ "http://iappfree.candou.com:8080/free/applications/limited//? Currency=rmb&page=%li ", PageIndex];
Nsurl *url =[nsurl urlwithstring:urlstring];
Read URL content as a string object
NSString *datastring =[nsstring stringwithcontentsofurl:url encoding:nsutf8stringencoding Error:nil];
Convert a string to a NSData object
NSData *data =[datastring datausingencoding:nsutf8stringencoding];
Read the contents of the URL directly into the NSData object
NSData *data =[nsdata Datawithcontentsofurl:url];
NSLog (@ "%@", data);
ID Json =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil];
NSLog (@ "%@", Json);
if ([Json Iskindofclass:[nsdictionary class]]) {
Dictionary method parsing
Nsarray *applications =[json objectforkey:@ "Applications"];
NSLog (@ "%@", applications);
_datalist =[applications Mutablecopy];
}else if ([Json Iskindofclass:[nsarray class]]) {
Array method parsing
}
}

UI---about synchronizing downloads

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.