Need to convert NSData to NSArray

大城市里の小女人 提交于 2019-11-27 08:15:26

问题


I am pulling down a plist from a URL using an NSURLConnection, which returns an NSData object. I would like to convert 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!!


回答1:


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




回答2:


Use NSKeyedArchiver for archiving object to data.

NSKeyedUnarchiver for unarchiving object from data:

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


来源:https://stackoverflow.com/questions/2255430/need-to-convert-nsdata-to-nsarray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!