我在这里遇到过其他类似的问题,但我不知道我做错了什么。我正在调用这个API:
https://coronavirus-tracker-api.herokuapp.com/v2/locations
它返回一个像这样的 JSON 对象:
{
"latest": {
"confirmed": 272166,
"deaths": 11299,
"recovered": 87256
},
"locations": [
{
"id": 0,
"country": "Thailand",
"country_code": "TH",
"province": "",
"last_updated": "2020-03-21T06:59:11.315422Z",
"coordinates": {
"latitude": "15",
"longitude": "101"
},
"latest": {
"confirmed": 177,
"deaths": 1,
"recovered": 41
}
},
{
"id": 39,
"country": "Norway",
"country_code": "NO",
"province": "",
"last_updated": "2020-03-21T06:59:11.315422Z",
"coordinates": {
"latitude": "60.472",
"longitude": "8.4689"
},
"latest": {
"confirmed": 1463,
"deaths": 3,
"recovered": 1
}
}
]
}
所以我编写了一个小程序来解析它,但我只能解析外部对象(“最新”),而内部数组(“位置”)始终返回nil。
代码在这里(即使 TCP 调用在 Playground 上不起作用):
https://play.golang.org/p/ma225d07iRA
明月笑刀无情
相关分类