我在这里定义了相同的类型,但是在编译时出现错误:
不能在作业 i 中使用问题(类型 []struct { Question questions.MasterQuestion })作为类型 []struct { Question questions.MasterQuestion "json:"question"" }
这是我的代码:
类型文件
type QuestionnaireInternal struct {
ID string `json:"id"`
Questionnaire InternalQuestionnaire `json:"questionnaire"`
Questions []struct {
Question MasterQuestion `json:"question"`
} `json:"questions"`
}
DAL 文件
qusIdxMap := make(map[string]struct{})
var questions []struct {Question questions.MasterQuestion}
for {
buf := idRows.NextBytes()
if len(buf) == 0 {
break
}
var ids []string
if de := json.Unmarshal(buf, &ids); de != nil {
return nil, de
}
for i := range ids {
if _, exists := qusIdxMap[ids[i]]; exists == false {
qusIdxMap[ids[i]] = struct{}{}
}
}
for j := range qus.Questions {
if _, exists := qusIdxMap[qus.Questions[j].Question.QuestionID]; exists {
*ERROR HERE:* **questions = append(questions, &qus.Questions[j])**
}
}
qus.Questions = questions
}
温温酱
相关分类