JSONに対応するRESTful APIがあります。私はこのようにそれを呼んでいる:JSONはきちんと辞書に入りますが、objectForKeyエラー
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
kProjectList];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
});
}
は、その後、私は私のfetchedData方法があります:私は// NSArrayのラインのコメントを解除した場合、私はそれで-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x6d81720
を取得
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
//NSArray *projects = [json objectForKey:@"name"]; //2
NSLog(@"name: %@", json); //3
}
を、私の辞書をコメントアウトログ:
(
{
"created_at" = "2012-04-04T01:46:51Z";
description = "First Project Created";
id = 1;
name = "Test 1";
"updated_at" = "2012-04-04T01:46:51Z";
},
{
"created_at" = "2012-04-04T01:47:23Z";
description = "Second Project Created";
id = 2;
name = "Test 2";
"updated_at" = "2012-04-04T01:47:23Z";
}
)
私はNSArrayを持っている他の同様の問題を読みました。NSDictionaryが必要です。この変更を行うと、まったく同じエラーが発生します(異なるインスタンス0x #######明らかに)。 –
あなたの質問は...ですか? –