繁体   English   中英

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

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

我在xcode中使用json的此方法中遇到此问题。(我的xcode版本为5)
这是带有错误的语句:

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];
    }
}

这是TouchJSON库的一部分。 您应该确保已在项目中包含该库。 还要确保已在.m文件顶部导入了适当的标头:

#import "CJSONDeserializer.h"

或更改您的代码以使用内置的NSJSONSerialization ,例如,替换显示以下内容的行:

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

上面写着:

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

暂无
暂无

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

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