开发者

how to convert NSString to NSMutableArray?

i have an NSString that is value in plist format. i download this string from url. but i dont wanna write it to a file. when the string comes Asynchronous, i want to put it to nsmutablearray. how can i convert string (in plist format) to nsmutablearray? there is some methods, initWithContentsOfURL, initWithContentsOfFile. but no intiwithstring.

this method works Synchronous: NSMutableArray *tmpArray = [[NSMutable开发者_开发知识库Array alloc] initWithContentsOfURL:url];


There is a -propertyList method in NSString.

NSMutableArray* tmpArray = [[theString propertyList] mutableCopy];
...
[tmpArray release];

Note that this method will throw an exception (i.e. throw) if the string is not in plist format. To have a better error checking, try to download the data as NSData, and use the NSPropertyListSerialization methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜