Я пытаюсь получить значения json, полученные с помощью запроса.
Но я не получаю значение foo1
, я пробовал все, но не могуполучить значение.
Появляется ошибка invalid operation
.
Вы можете мне помочь?
{
"result": {
"foo1": 1751,
"foo2": "2018-12-17T00:00:00-02:00",
}
}
url := "mysite"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
byt := []byte(string(body))
var dat map[string]interface{}
if err := json.Unmarshal(byt, &dat); err != nil {
panic(err)
}
fmt.Println(dat) //map[result:map[foo1:1751 foo2:2018-12-17T00:00:00-02:00]]
fmt.Println(dat["result"]) //map[foo1:1751 foo2:2018-12-17T00:00:00-02:00]]
foo1 := dat["result"]["foo1"] //invalid operation: dat["result"]["foo1"] (type interface {} does not support indexing)
fmt.Println(foo1)