Go - 构建 POST 正文,收到错误“无效的复合文字类型字符串”

我正在尝试在 Go 中构建一个 POST 正文,但我不断收到以下错误:


无效的复合文字类型字符串


下面是我的代码和结构的片段,我不知道我做错了什么?


postData := projectPostData{

    Filters: projectFilters{

        Name: string{ // <-- Error is referred to on this line 

            target,

        },

    },

}


type projectPostData struct {

    Filters projectFilters `json:"filters,omitempty"`

}


type projectFilters struct {

    Name string `json:"name,omitempty"`

}



大话西游666
浏览 143回答 1
1回答

哔哔one

您可以检查以下代码:package main&nbsp;import(&nbsp; &nbsp; "fmt")type projectFilters struct {&nbsp; &nbsp; Name string `json:"string,omitempty"`}type projectPostData struct {&nbsp; &nbsp; Filters projectFilters `json:"filters,omitempty"`}func main(){&nbsp; &nbsp; target := "test target"&nbsp; &nbsp; postData := projectPostData{&nbsp; &nbsp; &nbsp; &nbsp; Filters: projectFilters{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Name: target,&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; fmt.Println(postData)}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go