我正在编写一个 Python 脚本来将一些 JSON 文件输出到 Azure 上的 Cosmos DB。我的脚本如下所示:import loggingimport uuidimport jsonimport azure.functions as funcdef main(event: func.EventHubEvent, message: func.Out[func.Document]) -> None: event_body = event.get_body().decode('utf-8') logging.info('Python event trigger function processed an event item: %s',event_body) data = { "value": event_body, "insertion_time": event_body } message.set(func.Document.from_json(json.dumps(data)))输出是这样写的:{ "value": "{\n \"value\": \"66\",\n \"insertion_time\": \"2020-06-02T05:50:00+00:00\"\n}", "insertion_time": "{\n \"value\": \"66\",\n \"insertion_time\": \"2020-06-02T05:50:00+00:00\"\n}" }但是,我希望它是这样的:{ "value": "66", "insertion_time": "2020-06-02T05:50:00+00:00" }我该如何纠正这个问题?
1 回答
海绵宝宝撒
TA贡献1809条经验 获得超8个赞
您event_body似乎是一个 JSON 字符串,其中已经完全包含您想要的内容。看起来你不需要做任何事情,直接使用它:
message.set(func.Document.from_json(event_body))
添加回答
举报
0/150
提交
取消
