gpt4 book ai didi

go - Microsoft日历事件对Go结构的响应

转载 作者:行者123 更新时间:2023-12-01 21:09:33 24 4
gpt4 key购买 nike

一直试图将Microsoft的Graph API的响应解码到Go结构中,但是我不断收到错误消息“json:无法将对象解码到类型为[] struct {DateTime string” json:“dateTime”“的Go结构字段.value.start中; TimeZone字符串“json:” timeZone“”}“。
下面是我的结构:

type MicrosoftCalendarEventsResponse struct {   
Value []struct {
Etag string `json:"@odata.etag"`
Id string `json:"id"`
Subject string `json:"subject"`
Start []struct {
DateTime string `json:"dateTime"`
TimeZone string `json:"timeZone"`
} `json:"start"`
End []struct {
DateTime string `json:"dateTime"`
TimeZone string `json:"timeZone"`
} `json:"end"`
OriginalStartTimeZone string `json:"originalStartTimeZone"`
OriginalEndTimeZone string `json:"originalEndTimeZone"`
ICalUId string `json:"iCalUId"`
ReminderMinutesBeforeStart int `json:"reminderMinutesBeforeStart"`
IsReminderOn bool `json:"isReminderOn"`
} `json:"value"`
}
我收到的回复是这样的:
{"@odata.etag":"W/\"8COqS12xxxhwcMA==\"","id":"xxxxx","createdDateTime":"2019-12-05T17:09:41.018502Z","lastModifiedDateTime":"2019-12-05T17:09:41.8919929Z","changeKey":"xxxx","categories":[],"originalStartTimeZone":"W. Europe Standard Time","originalEndTimeZone":"W. Europe Standard Time","iCalUId":"xxx","reminderMinutesBeforeStart":15,"isReminderOn":true,"hasAttachments":false,"subject":"Something","bodyPreview":"","importance":"normal","sensitivity":"normal","isAllDay":false,"isCancelled":false,"isOrganizer":true,"responseRequested":true,"seriesMasterId":null,"showAs":"busy","type":"singleInstance","webLink":"xxx","onlineMeetingUrl":null,"isOnlineMeeting":false,"onlineMeetingProvider":"unknown","allowNewTimeProposals":true,"recurrence":null,"onlineMeeting":null,"responseStatus":{"response":"organizer","time":"0001-01-01T00:00:00Z"},"body":{"contentType":"html","content":""},"start":{"dateTime":"2019-12-17T17:00:00.0000000","timeZone":"UTC"},"end":{"dateTime":"2019-12-17T17:30:00.0000000","timeZone":"UTC"},"location":{"displayName":"","locationType":"default","uniqueIdType":"unknown","address":{},"coordinates":{}},"locations":[],"attendees":[],"organizer":{"emailAddress":{"name":"John Doe","address":"someone@somewhere.com"}}}
在其中您可以清楚地看到产生错误的部分:
"start":{"dateTime":"2019-12-17T17:00:00.0000000","timeZone":"UTC"}
谁能告诉我我做错了吗?尝试了几个小时而没有任何进展,我真的不知道出了什么问题。
其他东西,例如Etag,Id,Subject等,都可以正常工作。它只有嵌套的[]结构无效。

最佳答案

为了捕获日历事件(多个),有意义的是,顶层Values是结构的一部分。
但是,在特定的Value中,您的StartEnd字段也被定义为结构片段,这可能不是您想要的。
尝试一个简单的结构:

Start struct {
DateTime string `json:"dateTime"`
TimeZone string `json:"timeZone"`
} `json:"start"`

End struct {
DateTime string `json:"dateTime"`
TimeZone string `json:"timeZone"`
} `json:"end"`

关于go - Microsoft日历事件对Go结构的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63301364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com