c# - C# 如何将 JSON 插入 Google BigQuery 表架构
问题描述
我有一个复杂的 JSON 对象数组,其中包含 JSON 对象的嵌入式数组。举个例子,一个 JSON 对象可能看起来像……
{
"shopID": "12194",
"name": "Shop Name",
"timeZone": "US\/Eastern",
"timeStamp": "2020-11-30T13:25:13+00:00",
"Contact": {
"contactID": "90",
"Addresses": [
"ContactAddress": {
"address1": "123 Some Street",
"address2": "",
"city": "A city",
"state": "A state",
"zip": "12345",
"country": "United States",
"countryCode": "US"
}
],
"Emails": "",
"Websites": {
"ContactWebsite": {
"url": "www.companyname.com"
}
}
},
"TaxCategory": {
"taxCategoryID": "2",
"isTaxInclusive": "false",
"tax1Name": "Tax region name",
"tax1Rate": "0.07"
}
}
我无法修改上述格式...我正在调用一个将其作为响应返回的公共 API。
假设已在 Google BigQuery 中创建了相应的表架构,我如何简单地将这个 JSON 作为一行插入到表中?
我的代码看起来像这样......
bqc = BigQueryClient.Create("a-project-id");
var trShops = new TableReference()
{
ProjectId = "a-project-id",
DatasetId = "a-dataset-name",
TableId = "Shops"
};
# Call to my API data source that returns a JSON array of Shops...
content = await _lsrApiHelper.GetRawDataAsync(uri, currentOffset, _apiLimit);
# After call to API I deserialize the JSON response...
response = JsonSerializer.Deserialize<ShopResponseRoot>(content);
# Then I want loop through Shops in the List<ShopResponse> and insert them into BigQuery...
foreach (ShopResponse shop in response.Shop)
{
var newRow = new BigQueryInsertRow();
newRow.InsertId = "shopID";
newRow.Add(shop); # This is where I am struggling
bqc.InsertRow(trShops, newRow);
}
我正在努力研究如何使用 JSON 或 C# 对象来填充我想要插入 BigQuery 的数据。
非常感谢任何和所有指导。
解决方案
推荐阅读
- c++ - 在 OpenApi 中使用所选 JSON 库生成 pistache 服务器
- mysql - MySQL 每日时间覆盖率无差距
- html - 防止 Mailchimp 中的图像堆叠 (html/css)
- c# - Vector3.MoveTowards() 不起作用,无法修复?
- sql - 无法使用 pgAdmin4 读取 CSV 文件,无法打开文件 - 权限被拒绝
- postgresql - PostrgreSQL 尝试执行 plsh 函数
- html - 如何消除不需要的间隙
- 标签和一个 div
- perl - 写入 if 语句中的文件在 Perl 中不起作用
- xamarin - 无法在物理设备上调试(切换到虚拟设备)
- c# - 如何从 MS Access 数据库中的表结构中获取数值字段的精度和比例?