gpt4 book ai didi

ios - JSON页面仅访问第一页xcode

转载 作者:行者123 更新时间:2023-11-29 04:12:50 25 4
gpt4 key购买 nike

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

谢谢!

最佳答案

我认为您正在获取字典数组,因此当您触发查询时,您仅获得数组的第一个索引。因此尝试通过创建循环来获取所有数据。

尝试下面的代码。

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

}

关于ios - JSON页面仅访问第一页xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14168789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com