嗨,我有这段代码。
NSString *infoString = [NSString stringWithFormat:@"http://link.com/post.php?name=%@&street=%@&city=%@&state=%@&zip=%@&lat=%@&lon=%@", name, street, city, state, zip, str1, str2];
NSURL *infoUrl = [NSURL URLWithString:infoString];
NSData *infoData = [NSData dataWithContentsOfURL:infoUrl];
NSError *error;
responseDict = [NSJSONSerialization JSONObjectWithData:infoData options:0 error:&error];
NSString *responseString = [responseDict copy];
NSLog(@"responseDict: %@", responseString);
在控制台中,这将显示出来。
2012-06-14 22:37:04.022 PartyApp[20221:fb03] responseDict: {
status = 1;
}
无论如何,我可以做一个 if 语句来表明如果值为 1,则执行此操作,如果不是,则执行此操作。我在下面尝试过。
if ([responseDict objectForKey:@"status = 1"]) {
Then do this
}
但是它没有用,我做错了什么或我能做什么?
if ([responseDict objectForKey:@"status = 1"]) {
Then do this
}
应该是..
if ([responseDict objectForKey:@"status"]) {
//this will be done in case of 1
}else{
//this will be done in case of 0
}
只有status
才是关键,而不是你的全部......希望这有帮助。
更新:以上几行就足够了,因为它转弯 1 它会继续,否则在 0 的情况下条件为假,将转到 else
子句