python - 如何在 Python 中的 Json 中删除 Null:[]
问题描述
我一直坚持将 .Json 数据流式插入 BigQuery 但 .json 数据中的 Null:[] 会导致这样的错误。 我在 csv.DictReader 参数上搜索并添加了一些参数,但 Null 数据仍然存在。你能教我如何删除 Null: data in .Json 。太感谢了 。
def stream_data():
# BigQuery
client = bigquery.Client()
project_id = 'test_project'
dataset_name = 'test'
table_name = "test"
full_table_name = dataset_name + '.' + table_name
json_rows = []
with open('./test.csv','r') as f:
for line in csv.DictReader(f,skipinitialspace=False,quoting=csv.QUOTE_NONE):
line_json = dict(line)
json_rows.append(line_json)
errors = client.insert_rows_json(
full_table_name,json_rows,row_ids=[row['luid'] for row in json_rows]
) //stop making record that has same luid duplicately
if errors == []:
print("New rows have been added.")
else:
print("Encountered errors while inserting rows: {}".format(errors))
解决方案
我通过添加解决了这个问题del[None]
:
with open('./test.csv','r') as f:
for line in csv.DictReader(f):
del line[None]
line_json = dict(line)
json_rows.append(line_json)
推荐阅读
- cmake - 删除使用 link_libraries() 添加的库
- random - Solidity - 生成不依赖于输入的不可预测的随机数
- javascript - 在父边框的 View 中显示以下 TouchableOpacity 选项
- c# - 如何将数据库从测试(QA)服务器连接到 SSMS(SQL Server 2017)?
- c# - 由于 ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY,ASP.NET Core 3.0 应用程序无法在 Windows Server 2012 R2 上运行
- java - 从 AS 部署后无法访问 Endpoint,为什么?
- r - 浏览器中的 Rmarkdown 选项卡名称
- sql - 返回两个字段不同的查询结果 (Access 2010)
- angular - 当作为表达式调用时无法解析类装饰器的签名
- java - 为什么我不能将它上传到数据库?(JavaFX)