python - 用于输出 JSON 的 Python 脚本的属性值对输出错误
问题描述
我正在编写一个 Python 脚本来将一些 JSON 文件输出到 Azure 上的 Cosmos DB。我的脚本如下所示:
import logging
import uuid
import json
import azure.functions as func
def 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"
}
我该如何纠正?
解决方案
您event_body
似乎是一个 JSON 字符串,其中已经包含您想要的内容。看来您不需要做任何事情,只需直接使用它:
message.set(func.Document.from_json(event_body))
推荐阅读
- javascript - Javascript 在 ASP 母版页中的表单标记内不起作用
- ios - 如何知道在 swift 4 中实时 Firebase 的 childChanged 事件类型中更新了哪个子子项
- php - 如何在php的foreach循环中使用两个数组或三个数组插入数据库
- python - 将字符串/列表转换为数据框
- html - 使用 Twitter Bootstrap 4 在移动设备上增加空间
- swift - 在 Xcode 中导航到 UI 到相关控制器以及从控制器到 UI
- javascript - XMLHttpRequest GET 值不会输入到 mysqli_query SQL
- ios - 快速比较两个任意类型值的最佳方法
- python-3.x - Pandas 应用、map 和 iterrows 行为异常
- javascript - 如何从外部网站获取 HTML 表格值?