Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从url读取json_Json_Go_Google Sheets - Fatal编程技术网

从url读取json

从url读取json,json,go,google-sheets,Json,Go,Google Sheets,端点是在Google电子表格中创建的,如下所示: url01 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/1/public/values?alt=json" Git回购协议就在这里。。。在修复代码时,我将保存更新的代码。我的直觉是,当我导入文件时,我正在破坏结构。代码不打印任何内容。那么,我能得到一些关于什么地方出了问题的建议吗 packa

端点是在Google电子表格中创建的,如下所示:

url01 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/1/public/values?alt=json"
Git回购协议就在这里。。。在修复代码时,我将保存更新的代码。我的直觉是,当我导入文件时,我正在破坏结构。代码不打印任何内容。那么,我能得到一些关于什么地方出了问题的建议吗

        package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

type GSSS struct {
    Feed GSSSfeed `json:"feed"`
}

type GSSSfeed struct {
    Version string   `json:"version"`
    TITLE   GSSTitle `json:"title"`
    // Entry   []GSSSEntry `json:"entry"`
}
type GSSTitle struct {
    T string `json:"t"`
}

func main() {
    url01 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/1/public/values?alt=json"
    //url02 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/2/public/values?alt=json"
    //url03 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/3/public/values?alt=json"
    //url04 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/4/public/values?alt=json"
    //url05 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/5/public/values?alt=json"
    println("=============  starting main =============")

    // res, err := http.Get("https://www.citibikenyc.com/stations/json")
    res, err := http.Get(url01)
    if err != nil {
        panic(err.Error())
    }

    // body, err := ioutil.ReadAll(res.Body)
    // if err != nil {
    //  panic(err.Error())
    // }

    var m GSSS
    // err := json.Unmarshal(body, &m)
    //json.NewDecoder(res.Body).Decode(&m)
    // json.NewDecoder([]byte(body)).Decode(&m)

    // json.NewDecoder([]byte(res.Body)).Decode(&m)
    json.NewDecoder(res.Body).Decode(&m)

    //err := json.Unmarshal([]byte(body), &m)
    if err != nil {
        fmt.Println("Whoops...:", err)
    }

    fmt.Println("============  about to print m ============")
    fmt.Println(m.Feed.TITLE.T)
    fmt.Println("============  about to print m2 ============")
    fmt.Println(m.Feed)
    fmt.Println("============  about to print m3 ============")
    fmt.Println(m)
    fmt.Println("============  about to print m4 ============")
}

正如已经指出的,你对GSS的定义是错误的

这样效果更好一些:

package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

type GSSS struct {
    Version string `json:"version"`
    Feed GSSSfeed `json:"feed"`
}

type GSSSfeed struct {
    TITLE   GSSTitle `json:"title"`
    // Entry   []GSSSEntry `json:"entry"`
}
type GSSTitle struct {
    T string `json:"$t"`
}

func main() {
    url01 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/1/public/values?alt=json"
    //url02 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/2/public/values?alt=json"
    //url03 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/3/public/values?alt=json"
    //url04 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/4/public/values?alt=json"
    //url05 := "https://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/5/public/values?alt=json"
    println("=============  starting main =============")

    // res, err := http.Get("https://www.citibikenyc.com/stations/json")
    res, err := http.Get(url01)
    if err != nil {
        panic(err.Error())
    }

    // body, err := ioutil.ReadAll(res.Body)
    // if err != nil {
    //  panic(err.Error())
    // }

    var m GSSS
    // err := json.Unmarshal(body, &m)
    //json.NewDecoder(res.Body).Decode(&m)
    // json.NewDecoder([]byte(body)).Decode(&m)

    // json.NewDecoder([]byte(res.Body)).Decode(&m)
    json.NewDecoder(res.Body).Decode(&m)

    //err := json.Unmarshal([]byte(body), &m)
    if err != nil {
        fmt.Println("Whoops...:", err)
    }

    fmt.Println("============  about to print m3 ============")
    fmt.Println(m)
    fmt.Println("============  about to print m4 ============")
}
旋度-Ghttps://spreadsheets.google.com/feeds/list/168xdxefP3gGnrTGg2hwJoeRVfmbEuTB5plFTyd6I5Qo/1/public/values?alt=json 给出以{version:1.0,编码:UTF-8,提要:{xmlns:http://www.w3.org/2005/Atom,所以提要肯定不包含版本字段。。。