dongze5043 2018-12-02 13:54
浏览 42
已采纳

我正在尝试打印JSON

How can I print JSON? when I print I keep on getting random numbers in an array is there a way to print JSON instead of parsing it? Here's the function in the 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

 }

Here is the struct that I am using ( this get method will retrieve an artists' album from 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条回答 默认 最新

  • duanpai9945 2018-12-02 15:11
    关注

    If you are getting a load of numbers as a JSON body instead of text then probably it's an array of byte instead of a string. To fix this, convert to string

    response, _ := spot.Get(s, nil)
        fmt.Println(string(response))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?