golang无法解析json的解决办法:

json.Marshal
json.Marshal(hp)

注意:

struct

Golang HTTP请求Json响应解析方法

响应数据如下:

{
"number": 3,
"message": "success",
"people": [{
"craft": "ISS",
"name": "Chris Cassidy"
}, {
"craft": "ISS",
"name": "Anatoly Ivanishin"
}, {
"craft": "ISS",
"name": "Ivan Vagner"
}]
}

下面是一个http请求并解析json数据到结构体里的示例

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
type people struct {
Number int `json:"number"`
}
func main() {
url := "http://api.open-notify.org/astros.json"
spaceClient := http.Client{
Timeout: time.Second * 2, // Maximum of 2 secs
}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("User-Agent", "spacecount-tutorial")
res, getErr := spaceClient.Do(req)
if getErr != nil {
log.Fatal(getErr)
}
if res.Body != nil {
    defer res.Body.Close()
}
body, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
log.Fatal(readErr)
}
people1 := people{}
jsonErr := json.Unmarshal(body, &people1)
if jsonErr != nil {
log.Fatal(jsonErr)
}
fmt.Println(people1.Number)
}

推荐教程:《go语言教程》