gpt4 book ai didi

json - 如何解析由 cryptocompare API 生成的 JSON?

转载 作者:数据小太阳 更新时间:2023-10-29 03:41:04 25 4
gpt4 key购买 nike

<分区>

我正在尝试使用此 API 端点解析一些 JSON。

https://www.cryptocompare.com/api/data/coinlist/

我可以看到它使请求正常,然后我尝试解码响应的主体,它返回大量随机数。

如果我从调试器复制正文值,我会得到以下结果。

<[]uint8> (length: 643401, cap: 1048064)

这是我的代码。

url := fmt.Sprintf("https://www.cryptocompare.com/api/data/coinlist/")

fmt.Println("Requesting data from " + url)

req, err := http.NewRequest("GET", url, nil)

if err != nil {
log.Fatal("NewRequest: ", err)
return
}

client := &http.Client{}

resp, err := client.Do(req)

if err != nil {
log.Fatal("Do: ", err)
return
}

body, readErr := ioutil.ReadAll(resp.Body)

我希望能够从 JSON 中获取 Data 键内的所有内容,然后将其映射到结构。谁能看出我做错了什么?

下面是我到达端点时在浏览器中看到的示例。

 {
"Response": "Success",
"Message": "Coin list succesfully returned! This api is moving to https://min-api.cryptocompare.com/data/all/coinlist, please change the path.",
"BaseImageUrl": "https://www.cryptocompare.com",
"BaseLinkUrl": "https://www.cryptocompare.com",
"DefaultWatchlist": {
"CoinIs": "1182,7605,5038,24854,3807,3808,202330,5324,5031,20131",
"Sponsored": ""
},
"Data": {
"42": {
"Id": "4321",
"Url": "/coins/42/overview",
"ImageUrl": "/media/12318415/42.png",
"Name": "42",
"Symbol": "42",
"CoinName": "42 Coin",
"FullName": "42 Coin (42)",
"Algorithm": "Scrypt",
"ProofType": "PoW/PoS",
"FullyPremined": "0",
"TotalCoinSupply": "42",
"PreMinedValue": "N/A",
"TotalCoinsFreeFloat": "N/A",
"SortOrder": "34",
"Sponsored": false
},

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com