为了账号安全,请及时绑定邮箱和手机立即绑定

我正在尝试打印 JSON

我正在尝试打印 JSON

Go
森栏 2023-05-15 10:33:24
如何打印 JSON?当我打印时,我一直在获取数组中的随机数,有没有办法打印 JSON 而不是解析它?这是 main.go 中的函数 func sendpostget(word string) {// Create a new spotify objectspot := spotify.New("number", "number")// Authorize against Spotify firstauthorized, _ := 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"`}
查看完整描述

1 回答

?
阿晨1998

TA贡献2037条经验 获得超6个赞

如果您正在获取大量数字作为 JSON 正文而不是文本,那么它可能是字节数组而不是字符串。要解决此问题,请转换为字符串

response, _ := spot.Get(s, nil)
    fmt.Println(string(response))


查看完整回答
反对 回复 2023-05-15
  • 1 回答
  • 0 关注
  • 90 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信