【发布时间】:2015-05-26 05:57:47
【问题描述】:
我是 python 新手,我需要解析一个 JSON 文件,其中包含 HTTP 响应标头,我需要找到一组特定的标头类型,这些标头类型是否被使用。我的JSON 文件会是这样的:
"2236": {
"status": "200 OK",
"x-request-id": "13e98a1c93205a532810b2d34c92a04d",
"x-powered-by": "Phusion Passenger 4.0.21",
"transfer-encoding": "chunked",
"set-cookie": "ip_country=IN; path=/; expires=Fri, 25-May-2035 06:54:09 GMT",
"expires": "Thu, 28 May 2015 06:54:10 GMT",
"vary": "Accept-Encoding",
"connection": "keep-alive",
"server": "nginx/1.2.1",
"x-runtime": "0.780037",
"etag": "\"0ac30791df0dae1e4723d5360e82cee4\"",
"x-ua-compatible": "IE=Edge,chrome=1",
"cache-control": "max-age=259200, public",
"date": "Mon, 25 May 2015 06:54:10 GMT",
"content-type": "text/html; charset=utf-8",
"x-rack-cache": "miss"
},
"1681": {
"content-length": "56",
"accept-ranges": "bytes",
"vary": "Accept-Encoding,User-Agent",
"server": "PonyCakesv1.33.7",
"last-modified": "Fri, 22 May 2015 19:29:33 GMT",
"etag": "\"1c2665-2eb4-516b0ae026140\"",
"location": "http://www.olark.com/",
"date": "Mon, 25 May 2015 06:55:02 GMT",
"x-frame-options": "SAMEORIGIN",
"content-type": "text/html; charset=utf-8"
}
数字是 ID,我需要找到每个 ID 使用 'content-type' & 'x-frame-options'。
我的输出结果是这样的:
2236,content-type
1681,content-type,x-frame-options
我如何做到这一点?
【问题讨论】:
-
你已经尝试了什么?