Rafael Ruiz Muñoz
Rafael Ruiz Muñoz

Reputation: 5473

Http request on iOS. Not getting full string

I have this code to call the webservice to retrieve the coordinates given the address:

NSLog(@"\ndata:%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);

NSError* error;
NSDictionary* json = [NSJSONSerialization
                      JSONObjectWithData:data

                      options:kNilOptions
                      error:&error];
if (error != nil) {
    NSLog(@"\nerror:%@", error);
}

When I make 2 or 3 call, some of them I get the error != nil because the string is not full.

For example, if I've called "Ads" (http://maps.google.com/maps/api/geocode/json?address=ads) for the 3rd time or random time, I get this string:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Addison Airport",
               "short_name" : "Addison Airport",
               "types" : [ "establishment" ]
            },
            {
               "long_name" : "220",
               "short_name" : "220",
               "types" : [ "subpremise" ]
            },
            {
               "long_name" : "16051",
               "short_name" : "16051",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Addison Road",
               "short_name" : "Addison Rd",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Addison",
               "short_name" : "Addison",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Dallas County",
               "short_name" : "Dallas County",

enter image description here

so my parser doesn't work.

I repeat, this is on random times, I have to execute the code several times to reproduce it.

What am I doing wrong?

Thank you in advance.

Upvotes: 0

Views: 45

Answers (1)

user3191334
user3191334

Reputation: 1168

I think you forgot to collect all data-snippets of the whole response and past them together in one NSData object. This is just a part of the complete response. Maybe this post can help you.

Upvotes: 1

Related Questions