0

我从 JSON 查询返回 10,000 条记录,它被分成 102 页,每页大约有 100 个对象。前 100 个项目加载正常,但随后停止加载更多项目。如何让它进入下一页?这通常是如何完成的?此代码过去仅用于 sqlite。现在我已经使用核心数据将它转换为一个新的应用程序,但它卡在了第一页。有什么我做错了吗?

这是 JSON nslog(最后几行)

"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];

谢谢!

4

1 回答 1

1

我认为你得到了一个字典数组,所以当你触发你的查询时,你只会得到数组的第一个索引。所以尝试通过创建一个循环来获取所有数据。

试试下面的代码。

-(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
    }

}
于 2013-01-05T05:32:41.017 回答