json - 我正在尝试打印 JSON

标签 json api go spotify

如何打印 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/

相关文章:

docker - 如何启动 docker 容器并通过 golang 脚本运行一些命令?

go - 使用 Golang Exec 执行 Tmux

javascript - 从数组中获取三个最小值

java - Jackson 序列化和反序列化日期时间从/到 WCF 日期时间

javascript - 来自标签名称属性和值的 JSON 数组

api - 这两个 Google Maps Geocoding API URL 有什么区别?

javascript - 在 API 中使用不同的计算规则

java - 使用 Gson 反序列化元组数组

asp.net - 使用 asp.net 核心 API 从外部 API 获取数据

go - time.Sleep 在 VM 上睡了不正确的时间