2013-01-24 10 views
2

在一個JSON解析(與AFNetwork JSON消氣做),我有這樣的代碼片段:爲什麼__NSCFDictionary不是一種類的NSDictionary

if (![[data class] isKindOfClass:[NSDictionary class]]) { 
    DLog(@"%@ was not kind of class NSDictionary",[data class]); 
    return; 
} 

但由於種種原因,該If句話變成真的,該函數返回:

> __NSCFDictionary was not kind of class NSDictionary 

但不宜__NSCFDictionary是專門種NSDictionary類的?或者如果這是驗證的錯誤方式,那我該怎麼做呢?

UPDATE:

我試圖扭轉它,像這樣:

 if (![[NSDictionary class] isKindOfClass:[data class]]) { 
      DLog(@"%@ was not kind of class NSDictionary",[data class]); 
      return; 
     } 

還不行:

__NSCFDictionary不是那種類的NSDictionary

+0

請提供一個鏈接到'AFNetwork'。 – trojanfoe

+0

完成:) http://afnetworking.com –

+0

它看起來像你正在得到一個'__NCSFDictionary'因爲'AFNetworking'使用'NSJSONSerialization'(看代碼)。有相關的問題可能會幫助你:http://stackoverflow.com/questions/7156835/what-is-an-nscfdictionary和http://stackoverflow.com/questions/13300461/how-to-get-data-thats - 內部-nscfdictionary退回按slrequest-ON-OSX – trojanfoe

回答

6

根據docs

isKindOfClass: 
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class. (required) 

您正在使用

[data class] 

這將返回一個字符串..你必須使用對象/實例只即

if (![data isKindOfClass:[NSDictionary class]]) 
相關問題