I have this problem in this method that uses json in xcode.(My xcode version is 5)
This is the statement with the error:
NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
The error: Use of undeclared identifier 'CJSONDeserializer
'. but I already did declare this class in the project, so what I can do???
PLEASE HELP ME I REALLY NEED TO SOLVE THIS PROBLEM ASAP.
This is all the method.
- (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];
}
}
That's part of the TouchJSON library. You should make sure you've included that library in your project. Also make sure you have imported the appropriate header at the top of your .m file:
#import "CJSONDeserializer.h"
Or change your code to use the built in NSJSONSerialization
, e.g. replace the line that says:
NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
With one that says:
NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];