【发布时间】:2021-10-08 04:10:00
【问题描述】:
我正在尝试将 JSON 文件 ( Microsoft.Graph.Event ) 转换为 CSV 文件。我正在使用 Cinchoo ETL 来执行此操作。 这是我指的网址:
https://www.codeproject.com/Articles/1193650/Cinchoo-ETL-Quick-Start-Converting-JSON-to-CSV-Fil
这是我的代码:
using (var csv = new ChoCSVWriter(path + calendarId + ".csv").WithFirstLineHeader())
{
using (var json = new ChoJSONReader(path + calendarId + ".json")
.WithField("id")
.WithField("iCalUId")
.WithField("isAllDay")
.WithField("isCancelled")
.WithField("isOrganizer")
.WithField("isOnlineMeeting")
.WithField("onlineMeetingProvider")
.WithField("type")
.WithField("startTime", jsonPath: "$.start.dateTime")
.WithField("endTime", jsonPath: "$.end.dateTime")
.WithField("location", jsonPath: "$.location.displayname")
.WithField("locationType", jsonPath: "$.location.locationType")
.WithField("organizer", jsonPath: "$.organizer.emailAddress.name")
.WithField("recurrence", jsonPath: "$.recurrence.pattern.type")
)
{
csv.Write(json);
}
}
虽然我确实获得了 CSV,并且大多数标题和值都是正确的,但其中一些是奇怪的。一些标题在后面得到一个“_0”,一些值只是前一列的重复,而不是它应该是什么。 snapshot of csv file
我已经检查了我提前写出的 JSON 文件,但它们都很好。 我正在使用 .Net Core 3.1。
我只是一个初学者,非常感谢任何帮助或建议。谢谢。
编辑 添加 CSV 的快照,其中一些值只是前一列“startTime”的重复,而不是应有的值。
部分 JSON 文件
"start": {
"dateTime": "2020-05-17T00:00:00.0000000",
"timeZone": "UTC",
"@odata.type": "microsoft.graph.dateTimeTimeZone"
},
"end": {
"dateTime": "2020-05-18T00:00:00.0000000",
"timeZone": "UTC",
"@odata.type": "microsoft.graph.dateTimeTimeZone"
},
"location": {
"displayName": "asdfads",
"locationType": "default",
"uniqueId": "b0fd5377-937d-4fb2-b70a-0a696972b46c",
"uniqueIdType": "locationStore",
"@odata.type": "microsoft.graph.location"
},
【问题讨论】:
-
最好发布 JSON 文件的 sn-p。根据您的代码,看起来某些属性指向 JSON 数组值,这些值使用后缀 _0、_1 等输出它们。可能您需要更改 JSONPath,如
.WithField("startTime", jsonPath: "$.start.dateTime[0]")以更正它? -
或者试试
.WithField("startTime", jsonPath: "$.start.dateTime", isArray: false) -
TY 快速响应。这是完整 JSON 模式 link 的链接。您的我们的代码之一
.WithField("startTime", jsonPath: "$.start.dateTime", isArray: false)适用于后缀 _0,而.WithField("startTime", jsonPath: "$.start.dateTime[0]")没有。还有一个错误,当我更改列的顺序时,我仍然会遇到这个错误,CSV 中的一些值只是成为前一列的重复。 -
您能否发布预期的 CSV 输出?
标签: asp.net-core serialization microsoft-graph-api choetl