原始数据:
{'requestId': '26880.288', 'url': '', 'type': 'XHR', 'status': 200, 'headers': {'Accept-Ranges': 'bytes', 'Access-Control-Allow-Origin': 'https://www.chinamoney.com.cn', 'Ali-Cdn-Real-IP': '221.232.120.59', 'Connection': 'keep-alive', 'Content-Length': '1085', 'Content-Security-Policy': "default-src * 'unsafe-eval' 'unsafe-inline';", 'Content-Type': 'application/json', 'Date': 'Fri, 20 Sep 2024 06:06:19 GMT', 'ETag': '"43d-622845ff0aa86"', 'Last-Modified': 'Fri, 20 Sep 2024 03:10:00 GMT', 'Server': 'nginx', 'Via': '1.1 ID-7203207600254104 uproxy-6', 'X-Cache-Status': 'MISS from KS-CLOUD-HA-MP-11-02, MISS from KS-CLOUD-CD-CT-46-06', 'X-Cdn-Request-ID': '9e1fd701dc48c560a60357c8c625e83f', 'X-Content-Type-Options': ': nosniff', 'X-Frame-Options': 'ALLOW-FROM https://www.chinamoney.com.cn', 'X-XSS-Protection': '1; mode=block', 'x-link-via': 'cdct46:443;hamp11:443;'}, 'body': '{"head":{"version":"2.0","provider":"CWAP","req_code":"","rep_code":"200","rep_message":"","ts":1726801800168,"producer":""},"data":{"showDateEN":"20/09/2024 11:00","showDateCN":"2024-09-20 11:00"},"records":[{"termCode":"O/N","shibor":"1.9320","shibIdUpDown":"5.30","shibIdUpDownNum":5.3000000000,"termCodePath":"O/N"},{"termCode":"1W","shibor":"1.9290","shibIdUpDown":"1.80","shibIdUpDownNum":-1.8000000000,"termCodePath":"1W"},]}', 'base64Encoded': False}
body_json = json.loads(data['body'])
Log.Error(self,body_json)
# 从body_json中提取data和records部分
extracted_data = {
'data': body_json['data'],
'records': body_json['records']
}
Log.Error(self, body_json['records'])
try:
json_data= json.dumps(body_json['records'], indent=4)
Log.Error(self,f"Valid JSON: {json_data}")
except json.JSONDecodeError:
Log.Error(self,"Invalid JSON")