简体   繁体   English

使用未声明的标识符'CJSONDeserializer'??? 带有json的Xcode

[英]Use of undeclared identifier 'CJSONDeserializer' ??? Xcode with json

I have this problem in this method that uses json in xcode.(My xcode version is 5) 我在xcode中使用json的此方法中遇到此问题。(我的xcode版本为5)
This is the statement with the error: 这是带有错误的语句:

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

The error: Use of undeclared identifier ' CJSONDeserializer '. 错误:使用未声明的标识符' 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. 这是TouchJSON库的一部分。 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: 还要确保已在.m文件顶部导入了适当的标头:

#import "CJSONDeserializer.h"

Or change your code to use the built in NSJSONSerialization , eg replace the line that says: 或更改您的代码以使用内置的NSJSONSerialization ,例如,替换显示以下内容的行:

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

With one that says: 上面写着:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM