Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Modify a Github repo to get JSON asynchronously


I'm working on an iPhone app that needs to load data from my server in JSON or XML format. Since the app is free, I get huge amount of data and I get crash when launching app due to the long time when loading the data. So I understand that I should not get "all" the JSON at once but I have to load the data "pagened" [ little by little ] ..

I found this project that suits well my needs but can't get succes to modify it to my need :

https://github.com/nmondollot/NMPaginator

The project tooks Twitter api as a data source, what if I need to deal with a simple php file that returns JSON formatted data?

nb: I tried to contact the project developer but didn't get answer until now.

Thanks.

Replies

  • smithdale87smithdale87 Posts: 4,447iPhone Dev SDK Supporter @ @ @ @ @
    Your json source has to support pagination, you cannot just make it paged. It sounds like you are trying to load your JSON synchronously when your app launches. This is a bad idea in and of itself. At the very least, you should do this asynchronously. You may not need to worry about paging at all.
  • hafedhbahafedhba Posts: 3New Users

    Your json source has to support pagination, you cannot just make it paged. It sounds like you are trying to load your JSON synchronously when your app launches. This is a bad idea in and of itself. At the very least, you should do this asynchronously. You may not need to worry about paging at all.

    Ok I see, did you have a tutorial or code sample showing how to do this asynchronously ? thanks.

  • smithdale87smithdale87 Posts: 4,447iPhone Dev SDK Supporter @ @ @ @ @
    Can you show how you are currently doing it?
  • hafedhbahafedhba Posts: 3New Users

    Can you show how you are currently doing it?

    here how I was doing causing me pbm ..

    NSURL *url = [NSURL URLWithString:@"http://myfile.json"];
        
        NSString *response = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
        	   
        NSArray *jsonArray = [response objectFromJSONString];
        

  • Duncan CDuncan C Posts: 9,114Tutorial Authors, Registered Users @ @ @ @ @ @ @
    hafedhba said:

    Can you show how you are currently doing it?

    here how I was doing causing me pbm ..

    NSURL *url = [NSURL URLWithString:@"http://myfile.json"];
        
        NSString *response = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
        	   
        NSArray *jsonArray = [response objectFromJSONString];
        

    You need to use NSURLRequest and NSURLConnection. Take a look at the NSURLConnectionDataDelegate protocol. You'll need to implement the connection:didReceiveData:, connectionDidFinishLoading:, and connection:didFailWithError: methods at a minimum. There are lots of tutorials on the web that show how to do this.

    Alternately you could use a third party library like ASIHTTPRequest that does the work for you. That library is quite popular, although the creator is no longer maintaining it.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
Sign In or Register to comment.