我真的是可可开发的新手,所以请客气。无论如何,我正在尝试反序列化通过TouchJSON从服务器发送的JSON字符串,但是却收到'NSDictionary' may not respond to '+dictionaryWithJSONString:error:'的编译器警告。

我理解错误在说什么,但是我在项目中拥有所有TouchJSON文件,并且在app_Prefix.pch文件中有对NSDictionary_JSONExtensions.h的引用。当我键入命令时,我确实看到它显示在代码意义上,那么为什么它在编译器中失败?

这是失败的代码,我很感谢任何建议:

- (IBAction)authorizeUser:(id)sender {
 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.5/iOS"]];

 [request setRequestMethod:@"POST"];
 [request setPostValue:credentialsName.text forKey:@"Credentials.Name"];
 [request setPostValue:credentialsPassword.text forKey:@"Credentials.Password"];
 [request setPostValue:credentialsPIN.text forKey:@"Credentials.PIN"];
 [request startSynchronous];

 NSError *requestError = [request error];

 if (!requestError) {
  NSError *jsonError = NULL;
  NSDictionary *responseDictionary = [NSDictionary dictionaryWithJSONString:[request responseString] error:&jsonError]; /* <- ERROR... */

  status.text = [responseDictionary objectForKey:@"Success"];
 }
}


提前致谢!

更新

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import "ASIFormDataRequest.h"
    #import "CJSONDeserializer.h"
    #import "NSDictionary_JSONExtensions.h"
#endif


更新2

这就是“预处理”中显示的内容,并且文件和方法都在那里,因此应该可以正常工作吗?

# 10 "/Users/Alex/Documents/iPad/Classes/SignInViewController.m" 2
# 1 "/Users/Alex/Documents/iPad/TouchJSON/Extensions/NSDictionary_JSONExtensions.h" 1
# 32 "/Users/Alex/Documents/iPad/TouchJSON/Extensions/NSDictionary_JSONExtensions.h"
@interface NSDictionary (NSDictionary_JSONExtensions)

+ (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError;

最佳答案

问题是

+ (id)dictionaryWithJSONString:(NSString *)inJSON error:(NSError **)outError;


在实现文件(NSDictionary_JSONExtensions.m)中定义,但尚未在头文件(NSDictionary_JSONExtensions.h)中声明:

@interface NSDictionary (NSDictionary_JSONExtensions)
+ (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError;
@end




您可以修补头文件并添加所用方法的声明:

@interface NSDictionary (NSDictionary_JSONExtensions)
+ (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError;
+ (id)dictionaryWithJSONString:(NSString *)inJSON error:(NSError **)outError;
@end


直到开发人员解决此问题。我刚刚向TouchJSON的维护者发出了此问题的警报。

关于cocoa - 使用TouchJSON时,“NSDictionary”可能不会响应“+ dictionaryWithJSONString”……,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4824501/

10-15 02:08