开发者

Need to convert NSData to NSArray

I am pulling down a plist from a URL using an NSURLConnection, which returns an NSData object. I would like to conver开发者_高级运维t this to an NSArray. Can anyone help me?

I am refactoring a method that currently does a synchronous request to the URL, using arrayWithContentsOfURL: to get the NSArray.

Thanks!!


Use +[NSPropertyListSerialization dataWithPropertyList:format:options:error:] to convert the data, then check if the result -isKindOfClass:[NSArray class].


Use NSKeyedArchiver for archiving object to data.

NSKeyedUnarchiver for unarchiving object from data:

NSArray *object = [NSKeyedUnarchiver unarchiveObjectWithFile:self.receivedData];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜