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];
}
}
你爲什麼不使用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