Php 无法从填充了JSON数据的NSDictionary中提取数据

Php 无法从填充了JSON数据的NSDictionary中提取数据,php,json,ios5,Php,Json,Ios5,我刚刚开始为IOS5编写应用程序。我目前有一个PHP Web服务,应用程序调用它从数据库检索数据。在数据库中,我现在有3行,当我进入调试器时,字典有3个键/值对。但我无法检索任何值。我的代码如下: NSURL *myUrl = [[NSURL alloc]initWithString:@"http://localhost/~stephen-hill9/index.php"]; NSData *data = [[NSData alloc] initWithContentsOfURL:myUrl];

我刚刚开始为IOS5编写应用程序。我目前有一个PHP Web服务,应用程序调用它从数据库检索数据。在数据库中,我现在有3行,当我进入调试器时,字典有3个键/值对。但我无法检索任何值。我的代码如下:

NSURL *myUrl = [[NSURL alloc]initWithString:@"http://localhost/~stephen-hill9/index.php"];
NSData *data = [[NSData alloc] initWithContentsOfURL:myUrl];
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"Parsed Data: %@", json);
NSDictionary *bodyDictionary = [json objectForKey:@"Product_Desc"]; <-APP CRASHES HERE - INVALID KEY
NSLog(@"Parsed Data: %@", bodyDictionary);
我希望有人能帮忙——我相信问题一定是一些基本的问题

多谢各位


Stephen

好的,这里是一组字典,而不是字典本身。 试试这个:

NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSDictionary *bodyDictionary = [json objectAtIndex:0];

当然,这只会得到第一个对象,但你会想到…

如何从字典中提取数据?谢谢你的回答-我找不到NSDictionary的“objectAtIndex”方法:-SOops。。。抱歉-我刚刚将第一个字典json更改为一个数组,并将objectAtIndex提取到第二个字典中,它已经工作了。非常感谢你的帮助!很高兴帮助了你:考虑如果你想找的答案正确的话。
NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSDictionary *bodyDictionary = [json objectAtIndex:0];