2013-01-05 55 views
0

我從JSON查詢返回10,000條記錄,並將其分成102頁,每頁大約有100個對象。前100個項目加載正常,但它停止加載更多。我如何才能進入下一頁?這通常如何完成?這個代碼以前只適用於sqlite。現在我已經完成了使用核心數據將其轉換爲新應用程序的工作,但它陷入了第一頁。我做錯了什麼?JSON頁面只訪問第一頁xcode

這裏是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]; 

謝謝!

+0

可以請你發表一些代碼你已經試過了嗎? –

+0

當然,添加了一些代碼 –

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

} 
+0

似乎沒有循環。所以如果nslog告訴我102頁。這是否意味着102個字典?我如何循環到下一頁? –

+0

把你的API鏈接放到瀏覽器中,然後你將在JSON中得到響應,然後複製所有內容並粘貼到這裏:http://json.bloople.net你可以清楚地瞭解結構和輕鬆獲取所有數據。 –

+0

美好的時光,工作...謝謝 –