【发布时间】:2019-10-23 12:37:51
【问题描述】:
我有点卡住了,我能想到的解决方案都会以意大利面条式代码结束。
我有以下 JSON,我在 python 3 中创建了一个对象,我必须将值插入 PostgreSQL。
{
"name": "test",
"country": "DE",
"time": "21-Oct-2019 (09:58:01.694763)",
"toCurrency": ["EUR", "USD", "GBP"],
"fromCurrency": ["DKK", "DKK", "DKK"],
"buyMargin": ["1.2800", "1.2800", "2.0000"],
"sellMargin": ["1.2800", "1.2800", "2.0000"],
"unit": "M100"
}
我遇到了异常:can only concatenate str (not "list") to str
- 如何在 Python 中遍历这些列表并一次插入一个值?
同时每次都要插入'name'、'country'、'time'的其他值。
目前我可以插入这个 JSON:
{
"name": "test",
"country": "DE",
"time": "21-Oct-2019 (09:58:01.694763)",
"toCurrency": "EUR",
"fromCurrency": "DKK",
"buyMargin": "1.2800",
"sellMargin": "1.2800",
"unit": "M100"
}
【问题讨论】:
-
这些值是要插入
json列还是必须解析并插入8 个不同的列? -
它们将被插入到 8 个不同的列中
标签: python json python-3.x postgresql list