我想返回此域中的项目数。我知道count(*)返回一个名为Domain的项,其中包含一个名为Count的属性。我怎样才能获得伯爵的价值?
@try {
SimpleDBSelectRequest *selectRequest2 = [[SimpleDBSelectRequest alloc] initWithSelectExpression:@"select count(*) from %@"];
SimpleDBSelectResponse *selectResponse = [[AmazonClientManager sdb] select:selectRequest2];
for (SimpleDBItem *item in selectResponse.items) {
if ( [item.name isEqualToString:@"Domain"])
{
NSLog(@"Attributes = %@",[item.attributes objectAtIndex:0]);
}
}
}
@catch (AmazonServiceException *exception) {
NSLog(@"Exception = %@", exception);
}
我为属性获得了这个:
Attributes = {Name: Count,AlternateNameEncoding: (null),Value: 3,AlternateValueEncoding: (null),<SimpleDBAttribute: 0x8667120>}
如何从中获取价值3?
答案 0 :(得分:1)
selectResponse
应该有items
属性,这是SimpleDBReplaceableAttribute
个实例的可变数组。应该有一个name
属性为“Count”且其value
属性是计数的字符串表示形式。
这将是:
SimpleDBReplaceableAttribute *attribute = [[selectResponse items] objectAtIndex:0];
NSInteger count = [[attribute value] integerValue];
答案 1 :(得分:0)
这有效:
for (SimpleDBAttribute *attr in item.attributes) { if ([attr.name isEqualToString:@"Count"]) { int total = [attr.value intValue];