这个问题是我之前另一个问题 的延伸。
以下是我的测试代码,我不太明白为什么我的尝试将
以下是我的测试代码,我不太明白为什么我的尝试将
res
转换为 ListSociete
会出错:import (
"errors"
"fmt"
"github.com/jmcvetta/neoism"
)
type Societe struct {
Name string
}
type ListSociete []Societe
func loadListSociete(name string) (ListSociete, error) {
db, err := neoism.Connect("http://localhost:7474/db/data")
if err != nil {
return nil, err
}
res := []struct {
Name string `json:"a.name"`
}{}
cq := neoism.CypherQuery{
Statement: `
MATCH (a:Societe)
WHERE a.name = {name}
RETURN a.name
`,
Parameters: neoism.Props{"name": name},
Result: &res,
}
db.Cypher(&cq)
if len(res) == 0 {
return nil, errors.New("Page duz not exists")
}
r := res[0]
return ListSociete(res), nil
}
一个[]struct{Name string}
和一个[]struct{Name string `json:"a.name"`}
不同吗?
或者说一个ListSociete与一个[]struct{Name string}
不同吗?
谢谢。
json:"a.name"
添加到Societe
中是否有效?另外,使用res := Societe{}
有什么问题吗? - OneOfOne无法将res(类型[]struct { Name string "json:\"a.name\"" })转换为ListSociete类型
。 - Nicolas Marshallres := Societe{}
时,这并不是一个真正的选项,因为我需要标签从我的数据库查询中提取结果(而且Societe只是一个结构体,而res是一个结构体切片)。 - Nicolas Marshall