我正在尝试打印 JSON
I am trying to print JSON in go
如何打印 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 而不是解析它? 这是 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))