首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSJSONSerialization问题

NSJSONSerialization问题
EN

Stack Overflow用户
提问于 2012-06-15 13:44:57
回答 1查看 249关注 0票数 0

嗨,我有这个代码。

代码语言:javascript
复制
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);

在控制台中,这会显示出来。

代码语言:javascript
复制
2012-06-14 22:37:04.022 PartyApp[20221:fb03] responseDict: {
    status = 1;
}

我已经在下面尝试过了。

代码语言:javascript
复制
if ([responseDict objectForKey:@"status = 1"]) {
            Then do this
        }

但是它不起作用,我做错了什么,或者我能做什么?

EN

回答 1

Stack Overflow用户

发布于 2012-06-15 13:49:33

代码语言:javascript
复制
if ([responseDict objectForKey:@"status = 1"]) {
            Then do this
        }

应该是..

代码语言:javascript
复制
if ([responseDict objectForKey:@"status"]) {
            //this will be done in case of 1
        }else{
//this will be done in case of 0

}

只有status才是关键,而不是你的全部..希望这能有所帮助..。

update:上面的代码行足够了,因为它返回1,它将继续,否则,如果条件为0,则条件为false,并转到else子句

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11045215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档