JSON页面只访问第一页xcode

时间:2013-01-05 05:04:12

标签: ios json nsmanagedobject

我从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];

谢谢!

1 个答案:

答案 0 :(得分: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
    }

}