2013-10-10 39 views
1

我在使用JSON在Xcode這種方法這個問題(我的Xcode版本5)
這是錯誤的語句:使用未聲明的標識符'CJSONDeserializer'? 。Xcode中使用JSON

NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; 

錯誤:未聲明的標識符的使用「 CJSONDeserializer'。但我已經在項目中聲明瞭這個類,所以我可以做什麼?

請幫助我,我真的需要儘快解決這個問題。

這是所有的方法。

- (void) viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    NSURL *url = [NSURL URLWithString:@"http://localhost:8888/json.php"]; // Modify this    to match your url. 

    NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; // Pulls the URL 
    NSLog(jsonreturn); // Look at the console and you can see what the restults are 

    NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; 
    NSError *error = nil; 

    // In "real" code you should surround this with try and catch 
    @try { 
     NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; 
     if (dict) 
     { 
      rows = [[dict objectForKey:@"user"] retain]; 
     } 

     NSLog(@"Array: %@",rows); 

     [jsonreturn release]; 
    } 
} 
+0

你爲什麼不使用NSJSONSerialization JSONObjectWithData:選項:錯誤:?參考:https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html#//apple_ref/occ/clm/NSJSONSerialization/JSONObjectWithStream:options:error: – Claudio

回答

0

這是TouchJSON庫的一部分。你應該確保你已經在你的項目中包含了這個庫。另外,還要確保您已導入相應的頭在你的.m文件的頂部:

#import "CJSONDeserializer.h" 

或更改代碼,使用內置的NSJSONSerialization,例如更換這行:

NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; 

有了一個說:

NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];