I’m already doing downloads in my app using NSURLSession so I used my existing 
code to download and decode the data returned by the URL below and didn’t get 
an error. I am building against iOS 7.1 and I tried it out in the simulator.

Doing a brief search, it seems like when others are running into this error, 
they’re working with JSON data that really does have garbage at the end. Is it 
possible that you’re doing something like appending a null terminator or 
something else non-printable so that when you look at the data then it all 
seems OK?


On Apr 30, 2014, at 8:20 AM, Diederik Meijer | Ten Horses 
<[email protected]> wrote:

> Hi all,
> 
> I have Googled this issue for hours and tried various solutions suggested at 
> Stackoverflow, but can't seem to solve the following problem.
> 
> I am pulling JSON from here: 
> http://www.tenhorses.com/apps/meijburg/dotTAXDataHandler/dotTAXtaxNotesAPI.php
> 
> Both JSONLint, http://jsonformatter.curiousconcept.com and freeformatter.com 
> say this is valid JSON.
> 
> I am using the NSURLConnection delegate methods (appending data as it comes 
> in to a NSMutableData object) and are  serialising the downloaded data in the 
> didFinishLoading like so:
> 
>    NSError *error;
>    id jsonObject = [NSJSONSerialization JSONObjectWithData:self.container 
> options:NSJSONReadingAllowFragments error:&error];
>    if (error) {
>        NSLog(@"ERROR: %@", error);
>    }
>    else {
>        if ([self.type isEqual:@"people"] || [self.type isEqual:@"projects"] 
> || [self.type isEqual:@"taxNotes"]) jsonObject = [jsonObject 
> objectForKey:@"items"];
>        NSString *notificationName = [NSString 
> stringWithFormat:@"%@DataDownloaded", self.type];
>        [[NSNotificationCenter defaultCenter] 
> postNotificationName:notificationName object:nil userInfo:[NSDictionary 
> dictionaryWithObject:jsonObject forKey:@"jsonArray"]];
>        [sharedConnectionList removeObject:self];
>    }
> 
> 
> In short this sends off a notification with a pointer to an NSArray in case 
> the downloader object's type is 'people', projects' or 'taxNotes' and to a 
> NSDictionary in other cases.
> 
> Now here is the problem: although the JSON parses fine and populates a 
> UITableView without any issues, I am still getting the following error:
> 
> Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be 
> completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0xa2329a0 
> {NSDebugDescription=Garbage at end.}
> 
> I tested by creating an NSString from the data object and adding a few 
> characters at the end. Never does that reveal anything that should be there 
> at the end of the JSON string.
> 
> This, in itself, is slightly unsettling, but not critically wrong..
> 
> Has anybody here experienced a similar issue?
> 
> If so, can you tell me how to fix this?
> 
> Many thanks,
> 
> Diederik


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to