我正在尝试打印 JSON

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

}


森栏
浏览 91回答 1
1回答

阿晨1998

如果您正在获取大量数字作为 JSON 正文而不是文本,那么它可能是字节数组而不是字符串。要解决此问题,请转换为字符串response, _ := spot.Get(s, nil)     fmt.Println(string(response))
打开App,查看更多内容
随时随地看视频慕课网APP