JSON - API Response
Coddyの「Pythonで学ぶAPI」コースのレッスン 3/10。
APIレスポンスは、多くの場合JSONと呼ばれる形式です。
JSONはJavaScript Object Notationの略称です。JSONはPythonのネイティブな辞書型データに似ています。
これらのAPIレスポンスは以下のようになります:
{
"errors": [
{
"status": "422",
"source": {
"pointer": "/data/attributes/firstName"
},
"title": "Invalid Attribute",
"detail": "First name must contain at least two characters."
}
]
}Pythonの辞書と同じようにJSONを操作できます。
チャレンジ
簡単以下のJSONコードを使用して、"errors" キーの値を print してみてください。
これを行うには、dictionaries(辞書)がどのように機能するかをより深く理解している必要があります。
これは、Python Fundamentalsコースの辞書のセクションで説明されています。
自分で試してみよう
json = {
"errors": [
{
"status": "422",
"source": {
"pointer": "/data/attributes/firstName"
},
"title": "Invalid Attribute",
"detail": "First name must contain at least two characters."
}
]
}
### Write Your Code Below This LinePythonで学ぶAPIのすべてのレッスン
3Weather Fetch API Program
API Connection to ServerGET Request to ServerDisplaying Appropriate Results