小编Log*_*ood的帖子

将 json 数组解组到 go 结构中(数组位于 JSON 字符串的中间

我是围棋新手。我正在使用天气 API。我已经注释掉了导致错误的部分。我看到其他几个链接也有类似的问题,但是它们似乎都没有在 JSON 字符串中间包含数组。我确信有一种方法可以用切片定义结构。我似乎无法获得允许它的语法。这是我被困住的地方:

package main

import (
    "encoding/json"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

// WeatherData struct to collect data from the API call
type WeatherData struct {
    Wind Wind
    Sys  Sys
    // Weather Weather
    Name string `json:"name"`
}

////////////// ERROR when unmarshalling this struct /////////
// Weather provides basic weather info
// type Weather struct {
//  ID      int    `json:"id"`
//  Descrip string `json:"description"`
//  Icon    string `json:"icon"`
// }
/////////////////////////////////////////////////////////////

// Sys includes sunrise, sunset, country, etc.
type …
Run Code Online (Sandbox Code Playgroud)

arrays json struct go unmarshalling

3
推荐指数
1
解决办法
2092
查看次数

标签 统计

arrays ×1

go ×1

json ×1

struct ×1

unmarshalling ×1