2015-01-17 152 views
0

首先,我通過Amazon DynamoDB文檔無情地搜索並搜索了我能想到的每個論壇。iOS dynamoDB getItem結果不能正確顯示列表/集合

我想要做的事很簡單。我只是想在DynamoDB表上執行getItem命令並解析列表或字符串集的item屬性。

AWSDynamoDBGetItemInput *getItem = [AWSDynamoDBGetItemInput new]; 
getItem.tableName = @"tester"; 

AWSDynamoDBAttributeValue *hashValue = [AWSDynamoDBAttributeValue new]; 
hashValue.S = @"Washington"; 
getItem.key = @{@"aaa": hashValue}; 

[[dynamoClient getItem:getItem] continueWithBlock:^id(BFTask *task) { 
    if (!task.error) { 
     AWSDynamoDBGetItemOutput *response = task.result; 
     NSDictionary *customer = response.item; 
     NSLog(@"%@",customer); 
    } else { 
     NSLog(@"%@",task.error); 
    } 
    return nil; 
}]; 
  • 表名稱: 「測試」
  • hashKey: 「AAA」
  • ATTRIBUTE1:列表,名爲 「子選項卡」
  • attribute2:所謂的 「stringSet」 字符串設定

這裏是我得到的輸出

2015-01-17 00:19:51.535 DiscoveryPage[7157:302848] { 
"Sub Tags" = "<AWSDynamoDBAttributeValue: 0x7fafd1790000> {\n}"; 
aaa = "<AWSDynamoDBAttributeValue: 0x7fafd178f9a0> {\n S = Washington;\n}"; 
stringSet = "<AWSDynamoDBAttributeValue: 0x7fafd178fed0> {\n  
SS =  (\n  10,\n  11,\n  12,\n  13\n );\n}";} 

「Sub Tags」的輸出是一個「List」屬性......我怎麼解析這個?

對於字符串集,我可能會做一些令人毛骨悚然的字符串操作來獲取這個字符串集合中的4個元素(10,11,12,13),但這似乎很荒謬,我必須這樣做。 DynamoDB是否真的不給我輸出我的列表,並給我我的字符串設置爲一個巨大的字符串?

我錯過了什麼嗎?有沒有一個工具可以解析我丟失的DynamoDB getItemOutput?

回答

0

首先,確保您使用的是適用於iOS的最新版本的AWS Mobile SDK。如果你使用2.0.15或更高版本,你不需要解析customer,因爲它是already parsed。這是NSString/AWSDynamoDBAttributeValue對的NSDictionary對。你打印出整個字典,所以它看起來像是一個字符串,但事實上並非如此。您可以查看integration test以瞭解如何訪問Objective-C中字典中的數據。

+0

我得到同樣的問題。那我怎麼讀這個?您發佈的[集成測試]鏈接(https://github.com/aws/aws-sdk-ios/blob/master/AWSiOSSDKTests/AWSDynamoDBTests.m#L378)已不再。 – TheTiger