

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# GetItem
<a name="API_GetItem_v20111205"></a>

**重要**  
***本節涉及不該再用於新應用程式的已棄用 API 版本 2011-12-05。***  
 **如需目前低階 API 的文件，請參閱[Amazon DynamoDB API 參考](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/)。**

## 描述
<a name="API_GetItem_Description"></a>

`GetItem` 操作會傳回與主索引鍵相符的項目的一組 `Attributes`。如果沒有符合的項目，則 `GetItem` 不會傳回任何資料。

`GetItem` 操作預設會執行最終一致讀取。如果應用程式不接受最終一致讀取，則請使用 `ConsistentRead`。此操作可能比標準讀取需要更長的時間，但一定會傳回上次更新的值。如需更多詳細資訊，請參閱 [DynamoDB 讀取一致性](HowItWorks.ReadConsistency.md)。

## 請求
<a name="API_GetItem_RequestParameters"></a>

### 語法
<a name="API_GetItem_RequestParameters.syntax"></a>

```
// This header is abbreviated.
// For a sample of a complete header, see DynamoDB 低階 API.
POST / HTTP/1.1 
x-amz-target: DynamoDB_20111205.GetItem
content-type: application/x-amz-json-1.0 

{"TableName":"Table1",
 	"Key": 
		{"HashKeyElement": {"S":"AttributeValue1"},
		"RangeKeyElement": {"N":"AttributeValue2"} 
	},
	"AttributesToGet":["AttributeName3","AttributeName4"],
	"ConsistentRead":Boolean
}
```


****  

|  名稱  |  描述  |  必要 | 
| --- | --- | --- | 
|  TableName  |  包含所請求項目的資料表的名稱。 類型：字串  |  是  | 
|  Key  | 定義項目的主索引鍵值。如需主索引鍵的詳細資訊，請參閱 [主索引鍵](HowItWorks.CoreComponents.md#HowItWorks.CoreComponents.PrimaryKey)。類型：`HashKeyElement` 對其值的映射和 `RangeKeyElement` 對其值的映射。 | 是 | 
| AttributesToGet  | 屬性名稱陣列。如果未指定屬性名稱，則會傳回所有屬性。如果有部分屬性未找到，則這些屬性不會出現在結果中。類型：陣列 | 否 | 
| ConsistentRead  | 如果設定為 `true`，則會發送一致性讀取，反之則會使用最終一致性。類型：布林值 | 否 | 

## 回應
<a name="API_GetItem_ResponseElements"></a>

### 語法
<a name="API_GetItem_ResponseElements.syntax"></a>

```
HTTP/1.1 200 
x-amzn-RequestId: 8966d095-71e9-11e0-a498-71d736f27375 
content-type: application/x-amz-json-1.0
content-length: 144

{"Item":{
	"AttributeName3":{"S":"AttributeValue3"},
	"AttributeName4":{"N":"AttributeValue4"},
	"AttributeName5":{"B":"dmFsdWU="}
	},
"ConsumedCapacityUnits": 0.5
}
```


****  

|  名稱  |  描述  | 
| --- | --- | 
|  Item  | 包含所請求屬性。類型：屬性名稱值組映射。 | 
| ConsumedCapacityUnits | 操作所使用的讀取容量單位數目。此值顯示套用至佈建輸送量的數字。請求不存在項目會使用最小讀取容量單位，具體值依讀取類型而定。如需更多資訊，請參閱[DynamoDB 佈建容量模式](provisioned-capacity-mode.md)。 類型：數字 | 

## 特殊錯誤
<a name="API_GetItem_SpecialErrors"></a>

沒有此操作特定的錯誤。

## 範例
<a name="API_GetItem_Examples"></a>

 如需使用 AWS 開發套件的範例，請參閱 [在 DynamoDB 使用項目和屬性](WorkingWithItems.md)。

### 請求範例
<a name="API_GetItem_Examples_Request"></a>

```
// This header is abbreviated.
// For a sample of a complete header, see DynamoDB 低階 API.
POST / HTTP/1.1 
x-amz-target: DynamoDB_20111205.GetItem
content-type: application/x-amz-json-1.0 

{"TableName":"comptable",
	"Key":
		{"HashKeyElement":{"S":"Julie"},
		"RangeKeyElement":{"N":"1307654345"}},
	"AttributesToGet":["status","friends"],
	"ConsistentRead":true
}
```

### 回應範例
<a name="API_GetItem_Examples_Response"></a>

請注意，ConsumedCapacityUnits 值為 1，因為選用參數 `ConsistentRead` 已設定為 `true`。如果 `ConsistentRead` 已設定為 `false` (或未指定)，則回應為最終一致性，且 ConsumedCapacityUnits 數值為 0.5。

```
HTTP/1.1 200 
x-amzn-RequestId: 8966d095-71e9-11e0-a498-71d736f27375 
content-type: application/x-amz-json-1.0
content-length: 72

{"Item":
	{"friends":{"SS":["Lynda, Aaron"]},
	"status":{"S":"online"}
	},
"ConsumedCapacityUnits": 1
}
```