0

i am getting 10,000 records returned from a JSON query, and it is split into 102 pages with roughly 100 objects per page. The first 100 items are loaded fine, but then it stops loading more. How do I get it to go to the next page? How is this normally done? This code used to be for sqlite alone. Now I have finished transforming it into a new app using core data, but it gets stuck in the first page. Anything I am doing wrong?

here is the JSON nslog (last lines)

"PageNo":1,"TotalPages":102,"RecordCount":10163}




    -(void) serverDidFinishSending: (NSData *)responseData manager:(WebServiceCommunicator*)aManger requestURL:(NSURL *) url
        {
//Added the code below just to test out apple's JSON serializer
            NSError *error;
            NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
            NSLog(@"dictionary %@",dictionary);
            // Create the base object from factory.

//currently JSON serializer happens here 
    ReturnObjectFactory *aFactory = [[[ReturnObjectFactory alloc] init] autorelease];
        id object = [aFactory createObjectWithClassName:_className fromData:responseData];

        // Pass on the object to the target class and let that class deal with this object
        if(_target && [_target respondsToSelector:@selector(didRecieveObject:sender:)])
           [_target didRecieveObject:object sender:self];

Thanks!

William Falcon
  • 9,813
  • 14
  • 67
  • 110

1 Answers1

1

i Think you are getting a Array of Dictionary so when you firing your query , you are getting only first index of array. So try to get all data by creating a loop.

Try the below Code.

-(void) serverDidFinishSending: (NSData *)responseData manager:(WebServiceCommunicator*)aManger requestURL:(NSURL *) url
{
NSError *error;
id jsonObject = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&error];
NSLog(@"dictionary %@",jsonObject);

if ([jsonObject respondsToSelector:@selector(objectForKey:)])
     {
// This is a dictionary
// Create the base object from factory.
ReturnObjectFactory *aFactory = [[[ReturnObjectFactory alloc] init] autorelease];
// get your stuffs here
    }
else
    {
    // Treat as a Array
    }

}
Siba Prasad Hota
  • 4,779
  • 1
  • 20
  • 40
  • Did not seem to loop. So if the nslog is telling me 102 pages. Does that mean 102 dictionaries? How do I loop to the next page? – William Falcon Jan 05 '13 at 06:54
  • Put your API link in Browser , Then you will get the Response in JSON then copy all and Paste here: http://json.bloople.net You can get a clear idea on Structure and Easily can get all data. – Siba Prasad Hota Jan 05 '13 at 07:45