【发布时间】:2022-01-08 15:49:30
【问题描述】:
我目前收到此错误:
Invalid JSON text: "not a JSON text, may need CAST" at position 0 in value for column
这是试图插入的值:
{
"ath": 69045,
"ath_date": "2021-11-10T14:24:11.849Z",
"atl": 67.81,
"atl_date": "2013-07-06T00:00:00.000Z"
}
尝试插入我的数据库时。我相信这是由于 JSON 格式错误,但是我使用 json.dumps() 来转换我的字典。在过去的几个小时里,我尝试了几件事来尝试正确格式化它,但在两个错误之间碰壁了。
我尝试添加另一个级别并将其全部包装在另一个问题中建议的数组中,但是,这产生了相同的错误。
我的字典:
ticker_market_data[ticker] = {
"all_time": {
"ath": market_data["ath"]["usd"],
"ath_date": market_data["ath_date"]["usd"],
"atl": market_data["atl"]["usd"],
"atl_date": market_data["atl_date"]["usd"],
},
"price_change_percent": {
"1h": market_data["price_change_percentage_1h_in_currency"]["usd"],
"24h": market_data["price_change_percentage_24h"],
"7d": market_data["price_change_percentage_7d"],
"30d": market_data["price_change_percentage_30d"],
"1y": market_data["price_change_percentage_1y"],
},
}
问题项目是all_time 和price_change_percent。
这就是我创建要存储在数据库中的变量的方式:
all_time = json.dumps(ticker_market_data[ticker].get("all_time"))
price_change_percent = json.dumps(ticker_market_data[ticker].get("price_change_percent"))
【问题讨论】:
-
你是如何插入这些值的?还要贴出
all_time或price_change_percent的内容(取决于哪个导致错误)。 -
显示您尝试插入 MySQL 表的值。 我目前收到此错误这不是 MySQL 错误消息。
-
抱歉,我已更新以包含插入的值。在这种情况下,它是 all_time,因为这是要尝试的第一个。
-
这是 json.dumps() 的打印