0

我刚开始使用 Amazon Web Services SimpleDB 开展一个项目。在一种方法中,我试图通过使用select query.

代码如下所示:

AmazonSimpleDBClient *dbClienet = [[AmazonSimpleDBClient alloc]initWithAccessKey:_secret withSecretKey:_hiddenSecret];
NSString *countRequestString = [NSString stringWithFormat:@"select count(*) from %@",domain];
SimpleDBSelectRequest *countRequest = [[SimpleDBSelectRequest alloc]initWithSelectExpression:countRequestString];
SimpleDBSelectResponse *countResponse = [dbClienet select:countRequest];

这工作得很好。例如:连接有效,当我记录它时,响应似乎也是正确的:

{Items: (
"{Name: Domain,AlternateNameEncoding: (null),Attributes: (\n    \
"{Name: Count,AlternateNameEncoding: (null),Value: 2,AlternateValueEncoding: (null),<SimpleDBAttribute: 0x756f730>}\"\n),<SimpleDBItem: 0x7529d00>}"),NextToken: (null),{BoxUsage: 0.000023,{requestId: b683ed01-9e5f-9041-1ace-cbb0fdfaa799}}}

我接下来要做的是将值保存2NSInteger itemCount. 这是我挣扎的地方。我尝试了几件事,最远的是:

NSInteger itemCount = [[[[[countResponse.items objectAtIndex:0]attributes]objectAtIndex:1]value]integerValue];

这应该在我眼中起作用。但它会引发错误:

Multiple methods named 'value' found with mismatched result, parameter type or attributes

谁能指出我哪里出错了?我真的被困在这里了。

谢谢,塞巴斯蒂安

4

1 回答 1

2

感谢 geraldWilliam 的评论,我明白了:

    NSString *countRequestString = [NSString stringWithFormat:@"select count(*) from %@",domain];
    SimpleDBSelectRequest *countRequest = [[SimpleDBSelectRequest alloc]initWithSelectExpression:countRequestString];
    SimpleDBSelectResponse *countResponse = [dbClienet select:countRequest];
    NSArray* attributes = [[countResponse.items objectAtIndex:0]attributes];
    for (SimpleDBAttribute*attr in attributes) {
        if ([attr.name isEqualToString:@"Count"]) {
            itemCount = [attr.value integerValue];
        }
    }

这种方法有效。

于 2012-11-01T14:17:44.930 回答