0

I am very new to web services so please provide answer like to a complete beginner.

I am writing an app to consume json webservice data. But the service may return 15, 20, 200, 500, 1000, ... records.

I need to get them all.

The baseURI could be something like this:

http://api.service.com/json/cars/search?&c=suv&l=49.263569,-122.9847682&within=20&units=km

I know the service will return something like this:

{
  "total_items": "205",
  "page_number": "1",
  "page_size": "10",
  "page_count": "20",
  "cars": {
    "car": [
      { ... },
      { ... },
      ...
      { ... }
    ]
  }
}

So, I can see that there is 10 records per page and there is total of 20 pages. But I know this only once I issue the first request to get the data.

Here is my question: What is the way to get all 20 pages from a desktop application that shows these records in a a form with a scrollable control.

I thought something like:

getResponse(url, 1);  //get first page, this also gives me page_count from response

for (i := 2; i < page_count; i++){
  getResponse(url, i); // loop through number of pages to get each page till the end
}

So, above, I pass my url and page_number I want. First time I want 1st page, then I loop through all pages to get rest of pages by passing next page_number in each request.

Would this be common approach? How would I do it otherwise if this is not how it should be done?

Note that I don't have some kind of paging system on form, it is just a scrollable view holding all the results.

pixel
  • 9,653
  • 16
  • 82
  • 149
  • I think you can issue the request as the user scrolls down , you don't want to make all those calls if the user doesn't even scroll down , unless it's static and you can just populate it one time – loneshark99 Dec 25 '15 at 01:56
  • How do I do that? Thanks – pixel Dec 25 '15 at 02:02
  • Are you just asking how to deserialize JSON in c#? If so see [Deserializing JSON data to C# using JSON.NET](https://stackoverflow.com/questions/2546138) or [Deserialize JSON with C#](https://stackoverflow.com/questions/7895105/deserialize-json-with-c-sharp). – dbc Dec 25 '15 at 03:23
  • No, I am asking what is common way to get ALL pages returned by an url? loneshark99 understood my question. Thansk, – pixel Dec 25 '15 at 03:25
  • @dbnex14 I know the exact event that fires when the scroll at touches the end . There has to be some event , when that event fires just hookup your method to fetch the next page and keep a counter of what page is fetched. – loneshark99 Dec 25 '15 at 08:47

0 Answers0