3

I have this code:

NSDictionary *jsonGuardado = [self dictionaryFromJson:JSON];
NSLog(@"HOLA %@",jsonGuardado);
NSMutableArray *arrayCodigos = [jsonGuardado objectForKey:@"code"];
codigos = arrayCodigos;

(Codigos is an NSMutableArray)

The NSLOG return this:

HOLA (
        {
        code = 22051310;
    },
        {
        code = 22051311;
    },
        {
        code = 22051312;
    },
        {
        code = 22051313;
    }
)

But right after this, a message error says:

-[JKArray objectForKey:]: unrecognized selector sent to instance

I search this error in Google and here and all the questions I found not help me.

I'm using the JSONKit for make the dictionaryFromJson method.

4

3 回答 3

6

你试试这个,

NSArray *jsonGuardado = [self dictionaryFromJson:JSON];
NSLog(@"HOLA %@",jsonGuardado);
NSMutableArray *arrayCodigos = [NSMutableArray arrayWithArray:[jsonGuardado valueForKey:@"code"]];
NSLog(@"arrayCodigos %@", arrayCodigos);

它只会打印值。

于 2013-09-19T11:05:25.387 回答
2

在您的情况下,解析器返回一个数组而不是字典。

[self dictionaryFromJson:JSON]返回一个 Json 数组,但您在 NSDictionary 中捕获它

于 2013-09-19T10:55:27.700 回答
1

你的日志说它已经是NSArray. 你应该试试下面

NSMutableArray *jsonGuardado = [NSMutableArray array];
jsonGuardado = (id)[self dictionaryFromJson:JSON];
NSLog(@"HOLA %@",jsonGuardado);
NSMutableArray *arrayCodigos = [[jsonGuardado objectAtIndex:0] valueForKey:@"code"];
codigos = [arrayCodigos copy];
NSLog(@"Array %@",codigos);
于 2013-09-19T10:51:53.780 回答