本文介绍了使用NSLog打印NSData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用NSLog打印NSData对象的内容:
How can I print the contents of an NSData object using NSLog:
-(void) post:(NSString*) msg to:(NSString*) link{
NSString *myRequestString = [NSString stringWithFormat:@"message=%@", msg];
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: link]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: myRequestData];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
NSLog("%@", *returnData); //doesn't work
}
我想打印内容* returnData ...
I would like to print the contents of *returnData...
推荐答案
如果你这样做:
NSLog(@"%@", returnData);
NSData将以十六进制格式记录。我想这可能就是你想要的。
The NSData will be logged in hex format. I think that is probably what you are after.
如果你想把它变成一个字符串并记录字符串,你首先需要找出使用了什么字符集。 HTTP的默认字符集不是UTF-8,而是ISO-8859-1 。一种方法是检查charset部分的 Content-Type
标头。
If you want to turn it into a string and log the string, you first need to find out what character set was used. The default character set for HTTP is not UTF-8, it is ISO-8859-1. One way to do that is to examine the Content-Type
header for the charset section.
这篇关于使用NSLog打印NSData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!