Ios 如何从字典中访问字符串

Ios 如何从字典中访问字符串,ios,objective-c,Ios,Objective C,我从web服务获得以下响应,我需要获取字符串 错误:在数据库中找不到记录 如下所示: d = ( "Error: no record found in database." ); 这是我的密码 if([[[[dictiona objectForKey:@"d"] objectForKey:@""] objectAtIndex:0] isKindOfClass:[NSString class]] == YES) { UIAlertView *myAler

我从web服务获得以下响应,我需要获取字符串

错误:在数据库中找不到记录

如下所示:

d =     (
    "Error: no record found in database."
);
这是我的密码

 if([[[[dictiona objectForKey:@"d"] objectForKey:@""] objectAtIndex:0] isKindOfClass:[NSString class]] == YES)
    {
        UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Message" message:@"No Record Found"  delegate:nil  cancelButtonTitle:@"OK" otherButtonTitles: nil];

        [myAlertView show];
}

您的代码不应该检查第二个objectForKey,因为没有第二个NSDictionary可检查,因为您的第二个项是一个NSArray,它不通过键响应。这应该适合您:

if ([[[dictionary objectForKey:@"d"] objectAtIndex:0] isKindOfClass:[NSString class]])
{
    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Message" message:@"No Record Found"  delegate:nil  cancelButtonTitle:@"OK" otherButtonTitles: nil];

    [myAlertView show];
}

你的密码在哪里?字典是什么<代码>NSDictionary?您的web请求的内容类型是什么?是JSON吗?请尝试:
NSString*theString=[[dict objectForKey:@“MyArray”]objectAtIndex:0]
这不是一个有效的响应,请您的服务器人员发送xml响应或json响应,只需让他这样发送{“d”:“错误:在数据库中找不到记录。”}hello@troop231我尝试了您的代码,但应用程序崩溃控制台中出现以下消息-[[uu NSCFDictionary objectAtIndex:]:发送到实例0xC0D9180的无法识别的选择器请更新您的问题以显示第二个字典,因为您只显示了字典中的键,该字典是一个数组。