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 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿