iPhone NSURLConnection:如何处理返回的 NSData 对象?谷歌文档 API
我正在我的 iPhone 应用程序中使用 Google Docs API。我已经发送了正确的 POST 请求,并收到了响应以及一些 NSData。如果我对 NSData 对象进行 NSLog,我会得到:
NSData *returnedData = [NSURLConnection sendSynchronousRequest:request returningResponse:theResponse error:NULL];
NSLog(@"%@",returnedData);
//output : <4572726f 723d4261 64417574 68656e74 69636174 696f6e0a>
我认为 NSData 要么是 NSDictionary,要么是 NSArray。我应该收到几个返回的项目:一个 SID、一个 LSID 和一个 Auth。
如果我可以将 NSData 块转换为 NSDictionary,我就可以找到任意键的对象。
有人可以帮忙吗?
I'm working with the Google Docs API in my iPhone application. I've sent the proper POST request, and received a response along with some NSData. If I NSLog the NSData object, I get this:
NSData *returnedData = [NSURLConnection sendSynchronousRequest:request returningResponse:theResponse error:NULL];
NSLog(@"%@",returnedData);
//output : <4572726f 723d4261 64417574 68656e74 69636174 696f6e0a>
I think the NSData is either an NSDictionary or an NSArray. I'm supposed to receive a couple of items back, an SID, an LSID, and an Auth.
If I could turn the NSData chunk into an NSDictionary I could just find the object for whichever key.
Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须对数据进行解码。尝试以下操作:
当然,这取决于数据的编码方式。 NSUTF8StringEncoding 可能会起作用。
You will have to decode the data. Try the following:
Of course this will depend on how the data is encoded. NSUTF8StringEncoding might work instead.
您可能只需要将数据传递给 NSXMLParser
You may just need to pass the data to an NSXMLParser
处理 Web 数据的最佳方法是进行 NSXML 解析。无需解码数据,解析器将自行处理
The best way to deal with web data is Doing NSXML parsing. No need of decoding data the parser will handle itself