Note that there are some explanatory texts on larger screens.

plurals
  1. POfetch JSON data asynchronously
    text
    copied!<p>I want to fetch JSON data asynchronously. The data is set up in a way that one request will bring only 8 records. I need to send the requests repeatedly until the response becomes empty or returns less than 8 records. </p> <p>Currently, I have these methods in myviewcontroller.m class:</p> <pre><code>(void)myCallback:(id)sender { MyDataRequest *objMyDataRequest = [[[MyDataRequest alloc] init] autorelease]; objMyDataRequest.myRequiredVariableToGetAuthTokenDataResponse = classOfMyCallBack.someVariable; // Initiate getAuthToken request [objWishListRequest initiateGetAuthTokenRequest:self requestSelector:@selector(getAuthTokenDataResponse:)]; } </code></pre> <p>Now here is the definition of getAuthTokenDataResponse:</p> <pre><code>(void) getAuthTokenDataResponse:(NSData *)data { NSString *stringResponse = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; SBJsonParser *parser=[[SBJsonParser alloc]init]; NSDictionary *objDictionaryForStringResponse = [parser objectWithString:stringResponse]; [stringResponse release]; [parser release]; MyListRequest *objMyListRequest = [[[MyListRequest alloc] init] autorelease]; objMyListRequest.myRequiredValueToGetMyDataResponse = [objDictionaryForStringResponse objectForKey:@"Data"]; // Initiate GetMyDataResponse request [objMyListRequest initiateGetMyDataRequest:self requestSelector:@selector(getMyDataResponse:)]; } (void) getMyDataResponse:(NSData *)data { NSString *stringResponse = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; SBJsonParser *parser=[[SBJsonParser alloc]init]; NSDictionary *objGetMyDataRootDictionary = [parser objectWithString:stringResponse]; [stringResponse release]; [parser release]; NSDictionary *dataElements=[objGetMyDataRootDictionary objectForKey:@"Data"]; Wish *objMyData; for (NSDictionary* objGetMyDataRootDictionary in dataElements) { objMyData = [[Wish alloc]init]; //add different elements from dataElements into member variables of object objWish [self.myDataArray addObject:objMyData]; [objMyData release]; } [self.myDataTableView reloadData]; } </code></pre> <p>This method lies in MyDataRequest class:</p> <pre><code>(void)initiateGetMyDataRequest:(id)requestDelegate requestSelector:(SEL)requestSelector{ // Set the delegate and selector self.delegate = requestDelegate; self.callback = requestSelector; NSString* unescapedUrlString = [NSString stringWithFormat:@"http://test.mytesturl.com/core.svc/alldata/My/get/All/?token=%@&amp;search=&amp;page=1",myRequiredtokenparameter]; [self request:url]; } </code></pre> <p>I need to send multiple requests to the same url (with different parameter value i.e. value of page number) to fetch the results. How may I achieve it given the above scenario? The calls must be asynchronous. </p> <p>How should I make the actual flow between all these calls? How may I get the data of "all the pages" asynchronously?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload