Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9025667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:19:46+00:00 2026-06-16T06:19:46+00:00

I’m using a web service that returns a JSON formated data from a database

  • 0

I’m using a web service that returns a JSON formated data from a database on my server, this data will be displayed in some view on my iPhone app.

Since the app is free so I get thousands of rows on my DB and so of course in the JSON data I have to download.

How can I do a lazy loading for my JSON data? please any code lines will be very appreciated.

Thanks.

EDIT 1 :

in other words, I’m using an Sql request such as “select all from table”, then returns this data as JSON to my app.

How can I request a little number then add others etc .. ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:19:48+00:00Added an answer on June 16, 2026 at 6:19 am

    The term “lazy-loading” might not be entirely well suited to a single JSON response, and it might predispose us to one approach over another. So let me tackle what I presume is the underlying question, that you want to achieve improved user experience despite a very large server database:

    1. If the JSON is really large, you could always contemplate a “paging” metaphor, where you download the first x records, and then make subsequent requests for the next “pages” of server data. Given that additional server records can presumably be added between requests, you’ll have to think carefully about that implementation, but it’s probably easy to do.

    2. Another way of making the JSON more efficient, is to limit the data returned in the initial request. For example, the first request could return just identifiers or header information for all or a reasonable subset of the records, and then you could have subsequent requests for additional details (e.g. the user goes to a detail screen).

    3. A particular permutation of the prior point would be if the JSON is currently including any large data elements (e.g. Base64-encoded binary data such as images or sound files). By getting those out of the initial response, that will address many issues. And if you could return URLs for this binary data, rather than the data itself, that would definitely lend itself for lazy loading (as well as giving you the ability to easy download the binary information rather than a Base64 encoding which is 33% larger). And if you’re dealing with images, you might want to also contemplate the idea of thumbnails v large images, handling the latter, in particular, in a lazy-loading model.

    4. You could contemplate implementing a version of XML parsing that supports streaming. The standard NSXMLParser implementations try to load the entire XML feed (or as much as possible?) into memory at one time (despite method names that would suggest the contrary) before parsing proceeds. If your app used LibXML2 (such as in Apple’s AdvancedURLConnections sample), you can continue downloading and parsing the XML in the background while the initial data is presented to the user. This will simultaneously yield the benefit that most people associate with “lazy loading” (i.e. you don’t wait for everything before presenting the results to the user) and “eager loading” (i.e. it will be downloading the next records so they’re already ready for the user when they go there).

    For us to make more intelligent suggestions, you really need to share more information about the nature of your JSON and the data behind it, describe why you think “lazy loading” is the solution, etc. You might not want to go nuts on a particular solution until you do some analysis of the data (e.g. a JSON for thousands of rows can still be smaller than a single large image).


    Update:

    If you were going to adopt the first approach, you first need to change your web service so that in response to a request, it only delivers n records, starting at at a particular record number. You probably also need to return the total number of records on the server so you can give the user some visual cues as to how much there is to scroll through.

    Second, you need to update your iOS app to support this model. Thus, in your UI, as you’re scrolling through the results, you probably want your user interface to respond to scrolling events by showing either (a) actual results if you’ve already fetched it; or (b) some UI that visually indicates that the record in question is being retrieved and then asynchronously request the information from the server. If you were doing this in a UITableViewCell, it might do something like:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        [self initiateRequestForFirstSetOfData];
    }
    
    - (void)initiateRequestForFirstSetOfData
    {
        // asynchronously retrieve the data from the server:
        //   (a) retrieve the total number of records
        //   (b) retrieve the actual data for the first n records
        // and when this is done, dispatch a `[self.tableView reloadData]` back to the
        // main queue.
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.totalNumberOfRecordsOnServer;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        BOOL isAvailable = ... // do whatever logic to determine if this row has already been retrieved
    
        if (isAvailable)
        {
            // configure the cell like normal here
        }
        else
        {
            // configure the cell to indicate that a fetch is in progress here.
    
            // perhaps add a UIActivityIndicatorView and startAnimating it
    
            dispatch_async(backgroundQueue, ^{
    
                // initiate the request for the data (if you haven't already)
    
                dispatch_async(dispatch_get_main_queue(), ^{
    
                    // don't just update the UI here, but make sure the cell
                    // in question is still on screen by calling `UITableView`
                    // method `cellForRowAtIndexPath`, not to be confused with
                    // this method, which is a `UITableViewController` method.
    
                    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
                    if (cell)
                    {
                        // update the cell: sometimes you can get away with
                        // updating the cell directly, sometimes you want to
                        // just call something like:
                        //
                        // [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
                    }
                });
            });
        }
    
        cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
    
        return cell;
    }
    

    There are a whole bunch of refinements I might suggest over the above, fairly simplistic code, but hopefully it gives you the basic idea. You (a) figure out how many total rows of data there are; (b) you retrieve the first n records; (c) as the user scrolls to a record, you show it if you’ve got it, but if not, provide visually cue that you’re going to get that data for them asynchronously; and (d) when the data comes in, update the UI, if appropriate.

    Like I said, I’d probably pursue some refinements over the above code, e.g., I’d probably not embed the asynchronous retrieval in the view controller itself but rather do that in my model and have some delegate pattern to update the UI, I’d probably use operations queue rather than dispatch queue so I could cancel requests that we not needed any more, etc, but you get the basic idea.

    If you’re using a UICollectionViewController, it’s analogous to the above code. If you’re using a scroll view, the pattern is very similar, though you’d be responding to the UIScrollViewDelegate method scrollViewDidScroll instead (and you’d need to write code not only like the above, but also something that would release UIKit elements that had scrolled off the screen, too).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
For some reason, after submitting a string like this Jack’s Spindle from a text
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I have a view passing on information from a database: def serve_article(request, id): served_article

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.