Thanks Steve, that's promising, most likely something wrong in my
NSURLConnection code then, or the way I call it.
I don't think there's anything trailing in the JSON content, there really
isn'tt much in there his is the api server code:
<?php
header("Content-Type: application/json; charset=UTF-8");
$link = mysql_connect('localhost','[USERNAME','[PASSWORD') or die
(mysql_error($link));
mysql_query("SET NAMES 'utf8'");
mysql_select_db('[DB NAME') or die('Can't select database');
$query = "SELECT * FROM `[TABLE NAME]` ORDER BY `date` DESC LIMIT 0,
100";
$result = mysql_query($query) or die('ERROR EXECUTING QUERY
'.mysql_error($link));
$TaxNotes = array();
while ($row = mysql_fetch_array($result)) {
$UserName = $row['username'];
$DossierName = $row['dossierName'];
$Text = $row['text'];
$date = new DateTime($row['date']);
$Date = $date->format('d.m.Y');
$Hyperlink = $row['hyperlink'];
$Title = $row['title'];
$PictureURL = $row['pictureUrl'];
$Note = array(
"username" => $UserName,
"dossiername" => $DossierName,
"text" => $Text,
"date" => $Date,
"link" => $Hyperlink,
"title" => $Title,
"pictureUrl" => $PictureURL
);
array_push($TaxNotes, $Note);
}
$object = new stdClass();
$object->items = $TaxNotes;
echo json_encode($object);
?>
Op Apr 30, 2014, om 9:14 PM heeft Steve Christensen <[email protected]> het
volgende geschreven:
> 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]