このJsonはPOSTリクエストとして受信されます。今すぐ text
各キーの値を取得したいactions
配列POSTリクエストでjson属性を取得できません
私はリクエストを受け取るためにPythonのボトルを使用しています。 が必要な属性の値を取得するために、私はこの
word = request.forms.get('[attachments][actions][0][text]')
をした。しかし、これは必要な値を印刷しません。
{
"attachments": [
{
"title": "XYZ",
"title_link": "EDWE",
"text": "dxjhvgebndm",
"fields": [
{
"title": "Food",
"value": "$20",
"short": true
}
],
"actions": [
{
"name": "chess",
"text": "Approve",
"type": "button",
"value": "chess",
"style": "primary"
},
{
"name": "maze",
"text": "Decline",
"style": "danger",
"type": "button",
"value": "maze"
},
{
"name": "war",
"text": "More details",
"style": "default",
"type": "button",
"value": "war",
"confirm": {
"title": "Are you sure?",
"text": "Would you like to see more details of your expense?",
"ok_text": "Yes",
"dismiss_text": "No"
}
}
],
"image_url": "",
"thumb_url": "https://i.imgsafe.org/cf40eef.png",
"footer": "fghj",
"footer_icon": "https://i.imgsafe.org/cf2e0eef.png",
"ts": 1475057533
}
]
}
注:完全なJSONを受け取っていますが、問題は正しい属性を取得することにあります。これにより
EDIT 私はあなたがすべての辞書のアイテムにアクセスする方法はありませんPOSTリクエスト
import json
from bottle import route, run, request
import urllib
@route('/ocr_response', method='POST')
def ocr_response():
body = request.body.read()
word = request.forms.get('[attachments][actions][0][text]')
print word
print body
if __name__ == "__main__":
run(host='0.0.0.0', port=80, debug=True)
添付ファイルは配列ですが、あなたのgetは完全に間違っているようです。 –
体からjsonを読み込もうとしていますか? JSONとして 'body'をパースするのではなく' request.forms.get'を使っているのはなぜですか? –
Ohh shit、私は直接JSONとして体を解析することができた 真剣に私の悪い – Guru