简体   繁体   English

从NSData对象获取信息

[英]Getting info from NSData object

How would I get returningResponse (into say, a NSString) from the following code: 我将如何从以下代码中returningResponse (即NSString):

NSURLResponse* response;
NSError* error;
NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];

I think I can get the info that I need into a string but I can't call anything on response because it's null. 我想我可以将所需的信息保存到字符串中,但是我不能在response调用任何内容,因为它为null。 Therefore, I assume that I need to call something on result . 因此,我假设我需要在result上调用某些东西。 The problem is, I don't know what to call. 问题是,我不知道该怎么打。

(The URL request has been coded prior to the code sample. I know that that works.) I want to be able to detect if the request as successful. (URL请求已在代码示例之前进行了编码。我知道这是可行的。)我希望能够检测到请求是否成功。

According to the documentation for the URL loading system : 根据URL加载系统文档

If NSURLConnection is unable to download the URL the method will return nil and any available NSError instance by-reference in the appropriate parameter. 如果NSURLConnection无法下载URL,则该方法将返回nil,并在适当的参数中按引用返回任何可用的NSError实例。

So, see what's in your "error" parameter to find out what the problem is. 因此,请查看“错误”参数中的内容以找出问题所在。

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

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