我正在使用json-famework available on github 。我在我的项目中添加了该项目的引用,在我的 viewController 中添加了 header 搜索路径并导入了 JSON.h 文件。我正在尝试实现以下代码,它给了我这个错误,即 JSONRepresentation 是 NSDictionary 对象的无法识别的选择器。在这种情况下我做错了什么吗?请引导我完成。
NSDictionary * profileDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:user.userId, user.userVia, user.userName, user.firstName, user.lastName, user.emailId, user.contactNumber, user.gender, user.alternateNumber, user.weight, user.height, user.city, user.loginId, user.imageType, user.imageFileName, user.dob,nil]
forKeys:[NSArray arrayWithObjects:@"Id", @"UserVia", @"UserName", @"FirstName", @"LastName", @"EmailID", @"ContactNumber", @"Sex", @"AlternateNumber", @"weight", @"Height", @"City", @"LoginId", @"ImageType", @"ImageFileName", @"DOB", nil]];
NSString *jsonString = [profileDictionary JSONRepresentation];
最佳答案
您是否也将 .m 文件编译到您的项目中?
仅包含 .h 文件即可让代码编译。如果没有编译 .m 文件,它将在运行时崩溃并出现您所看到的错误。
关于iphone - -[__NSCFDictionary JSONRepresentation] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5537679/