0
驗證NSString是否屬性列表的最佳方式是什麼?如果我調用NSString的-propertyList方法,它將拋出一個異常,如果它不能解析字符串。NSString屬性列表問題
驗證NSString是否屬性列表的最佳方式是什麼?如果我調用NSString的-propertyList方法,它將拋出一個異常,如果它不能解析字符串。NSString屬性列表問題
在NSPropertyListSerialization
上使用+propertyListWithData:options:format:error:
來嘗試解析數據,如果不能,它可以通過一些診斷程序返回NSError
對象。例如:
NSString *plist = ...;
NSError *e = nil;
NSPropertyListFormat format;
id obj = [NSPropertyListSerialization
propertyListWithData:[plist dataUsingEncoding:NSUnicodeStringEncoding]
options:NSPropertyListImmutable
format:&format
error:&e];
的完美解決方案 – 2012-02-08 09:51:16
捕獲異常 – Felix 2012-02-08 09:06:36
@ phix23我寧願驗證數據 – 2012-02-08 09:10:07