2

How do I do partial download of JSON Data using NSConnection ?

Nabil Sham
  • 2,305
  • 4
  • 26
  • 38

1 Answers1

2

Can you provide a little bit more information about what you're trying to accomplish? I assume that you mean you would like to start processing the json before it is completely finished downloading. One thing you could look at the didReceiveData method that you can implement for the NSUrlConnection's delegate:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

You could parse through the data as it comes down, and when you have enough JSON to parse you could begin processing it well before it is completely downloaded. Of course, that means you will probably have to parse the json string yourself rather than use one of the json parsers that expects a fully formed json string.

Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
  • I am supposed to load data and present it in tableview for limited number of raws, and load more data as user scroll the table. Like if you are loading movies information, you load 10 movies. and stop the loading and continue only if hte user scroll down. ( I would have vote up your answer if I had enough reputation) – Nabil Sham Nov 03 '12 at 05:50
  • I see ... generally speaking, you do that with APIs that support paging. So for example you would make the first request and get back 10 movies explicitly; when the user reaches the bottom you can then do a second API request to get entries 11-20. In each case, you wouldn't really bother with incrementally loading the JSON, you would parse the entire result. – Joel Martinez Nov 04 '12 at 14:22