亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我正在嘗試打印 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 關注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號