我试图解析JSON数组并返回它们
我发现我可以在Python的HttpTrigger函数之外使用类似的东西
response['Body'] = [json.loads(item['Body']['bytes']) for item in response]
我想在我的HTTP触发器函数中这样做
我想象的是这样的:
with open('json_file.json','rb') as file:
jsonStr = file.read()
return func.HttpResponse(json.loads(jsonStr)['Body']['bytes'] for jsonStr item in func.HttpResponse, status_code=200)
其中json_file.json是包含以下内容的文件
json_file.json
[
{"id":1,"receiver":"77777777","message":{"test":" test signal","VehId":3,"DriverId":2,"GUID":"1s3q1d-s546dq1-8e22e","LineId":2,"SvcId":2,"Lat":-64.546547,"Lon":-68.546547,"TimeStamp":"2021-03-18T08:29:36.758Z","Recorder":"dq65ds4qdezzer","Env":"PRD"},"operator":20404,"sender":"MSISDN","binary":1,"sent":"2021-03-29T08:29:36.758Z"},
{"id":1,"receiver":"77777777","message":{"test":" test signal","VehId":3,"DriverId":2,"GUID":"1s3q1d-s546dq1-8e22e","LineId":2,"SvcId":2,"Lat":-64.546547,"Lon":-68.546547,"TimeStamp":"2021-03-18T08:29:36.758Z","Recorder":"dq65ds4qdezzer","Env":"PRD"},"operator":20404,"sender":"MSISDN","binary":1,"sent":"2021-03-29T08:29:36.758Z"},
{"id":1,"receiver":"77777777","message":{"test":" test signal","VehId":3,"DriverId":2,"GUID":"1s3q1d-s546dq1-8e22e","LineId":2,"SvcId":2,"Lat":-64.546547,"Lon":-68.546547,"TimeStamp":"2021-03-18T08:29:36.758Z","Recorder":"dq65ds4qdezzer","Env":"PRD"},"operator":20404,"sender":"MSISDN","binary":1,"sent":"2021-03-29T08:29:36.758Z"}
]
我知道返回不能与“func.HttpResponse”一起使用,但我不知道如何使用Python中的HTTP触发器函数循环遍历文件中的所有JSON对象
问候
相关问题 更多 >
编程相关推荐