我如何从 HTTP 响应 (python) 中提取 JSON
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 是你的字符串
我从 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 是你的字符串