Search code examples
iphoneiosnslog

how to nslog nsdata as a string


I am trying to log some data I am receiving as a string so i can see it in english. How ever when i try this I am getting (null) in the terminal.

This is what I am doing

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // do something with the data

    NSLog(@"%@", receivedData); //this pumps out the data representation
    NSString *myString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
    NSLog(@"%@", myString); //this pumps out (null)
}

I have no idea why this is happening.. i think I'm doing it right.


Solution

  • This means that the data is not UTF8 encoded. You might be splitting a multi-byte character for instance.