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];
精彩评论