![](/img/trans.png)
[英]How can I properly extract a JSON object returned in a HTTP response in Python?
[英]how can i Extract JSON from HTTP Response (python)
我從 lambda api 網關得到這個。 我怎樣才能得到 {\\n "a":"b",\\n "c":"d",\\n "e":"f",\\n "g":"h"\\n} 到 json 樣式?
"------WebKitFormBoundarySfqiG2UABUZYF7Ir\r\n
Content-Disposition: form-data;
name=\"upload-file\";
filename=\"example.json\"\r\n
Content-Type: application/json\r\n\r\n
{\n \"a\":\"b\",\n \"c\":\"d\",\n \"e\":\"f\",\n \"g\":\"h\"\n}
\r\n------WebKitFormBoundarySfqiG2UABUZYF7Ir--"
我想讓這個 {\\n "a":"b",\\n "c":"d",\\n "e":"f",\\n "g":"h"\\n}
至
{
"a":"b",
"c":"d",
"e":"f",
"g":"h"
}
你如何處理回應以獲得這個?
試試這個
import json
result = json.loads(x[x.find('{'): x.find('}')+1])
x 是你的字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.