如何打印 JSON?当我打印时,我一直在获取数组中的随机数,有没有办法打印 JSON 而不是解析它? 这是 main.go 中的函数
func sendpostget(word string) {
// Create a new spotify object
spot := spotify.New("number", "number")
// Authorize against Spotify first
authorized, _ := spot.Authorize()
if authorized {
// If we ere able to authorize then Get a simple album
// s := join("artists/", phone)
s := "artists/xxxx/albums?market=ES&limit=2"
fmt.Println(s)
response, _ := spot.Get(s, nil)
fmt.Println(response)
}
// Parse response to a JSON Object and
}
这是我正在使用的结构(此 get 方法将从 spotify API 检索艺术家的专辑)
type Albums struct {
Albums []Album `json:"users"`
}
type Album struct {
AlbumType string `json:"album_type"`
Href string `json:"href"`
ID string `json:"id"`
}
最佳答案
如果您正在获取大量数字作为 JSON 正文而不是文本,那么它可能是字节数组而不是字符串。要解决此问题,请转换为字符串
response, _ := spot.Get(s, nil)
fmt.Println(string(response))
关于json - 我正在尝试打印 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53580927/