简体   繁体   English

如何nslog nsdata作为字符串

[英]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. 但是,当我尝试这个时,我在终端中得到(null)。

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. 我不知道为什么会这样。我想我做对了。

This means that the data is not UTF8 encoded. 这意味着数据不是UTF8编码的。 You might be splitting a multi-byte character for instance. 例如,您可能正在拆分多字节字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM