0

嗨,我有这个代码。

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
        }

但它没有用,我做错了什么或者我能做些什么?

4

1 回答 1

0
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子句

于 2012-06-15T05:49:33.413 回答