努力瞭解如何反序列化從AWS DynamoDB發送的json對象。 我能夠成功調用dynamoDB.describeTable(describeTableInput!),並收到一份詳細的迴應......Swift 3 AWS DynamoDB json響應反序列化
2017-02-08 20:30:36.054 AWS_Test[84241:3626357] AWSiOSSDK v2.5.0 [Debug] AWSURLResponseSerialization.m line:63 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body:
{"Table":{"AttributeDefinitions":[{"AttributeName":"Author","AttributeType":"S"},{"AttributeName":"ISBN","AttributeType":"S"}],"CreationDateTime":1.486165623131E9,"GlobalSecondaryIndexes":[{"IndexArn":"arn:aws:dynamodb:ap-southeast-2:xxxxxxxxxxxxxxx:table/Books/index/ISBN-index","IndexName":"ISBN-index","IndexSizeBytes":94946,"IndexStatus":"ACTIVE","ItemCount":1780,"KeySchema":[{"AttributeName":"ISBN","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"NumberOfDecreasesToday":0,"ReadCapacityUnits":5,"WriteCapacityUnits":5}},{"IndexArn":"arn:aws:dynamodb:ap-southeast-2:xxxxxxxxxxxxxx:table/Books/index/Author-index","IndexName":"Author-index","IndexSizeBytes":94946,"IndexStatus":"ACTIVE","ItemCount":1780,"KeySchema":[{"AttributeName":"Author","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"NumberOfDecreasesToday":0,"ReadCapacityUnits":5,"WriteCapacityUnits":5}}],"ItemCount":1780,"KeySchema":[{"AttributeName":"ISBN","KeyType":"HASH"}],"ProvisionedThroughput":{"NumberOfDecreasesToday":0,"ReadCapacityUnits":5,"WriteCapacityUnits":5},"TableArn":"arn:aws:dynamodb:ap-southeast-2:xxxxxxxxxxxxxxxxx:table/Books","TableName":"Books","TableSizeBytes":94946,"TableStatus":"ACTIVE"}}
我的函數調用迪納摩...
func describeTable() {
let dynamoDB = AWSDynamoDB.default()
let describeTableInput = AWSDynamoDBDescribeTableInput()
describeTableInput?.tableName = "Books"
let tableDescription = dynamoDB.describeTable(describeTableInput!) as! AWSTask<AnyObject>
let jsonResult: NSDictionary = try JSONSerialization.JSONObjectWithData(Data, options: JSONSerialization.ReadingOptions.MutableContainers) as! NSDictionary
print(jsonResult.object(forKey: "ItemCount")!)
// let's dump everything to see what was returned
dump(tableDescription)
}
但我一直在努力幾天來試圖解決如何反序列化反應並存儲在我自己的字典中。
任何人都可以協助!?謝謝!