2012-02-08 56 views
0

驗證NSString是否屬性列表的最佳方式是什麼?如果我調用NSString的-propertyList方法,它將拋出一個異常,如果它不能解析字符串。NSString屬性列表問題

+0

捕獲異常 – Felix 2012-02-08 09:06:36

+0

@ phix23我寧願驗證數據 – 2012-02-08 09:10:07

回答

1

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]; 
+0

的完美解決方案 – 2012-02-08 09:51:16