为什么我无法解析具有嵌套数组的json与Unmarshal

问题描述 投票:0回答:1

我想在Go中使用json.Unmarshal解析此json。>>

{
    "quotes": [
        {
            "high": "1.9981",
            "open": "1.9981",
            "bid": "1.9981",
            "currencyPairCode": "GBPNZD",
            "ask": "2.0043",
            "low": "1.9981"
        },
        {
            "high": "81.79",
            "open": "81.79",
            "bid": "81.79",
            "currencyPairCode": "CADJPY",
            "ask": "82.03",
            "low": "81.79"
        }
    ]
}

源返回有关解析结果的{[]}


type GaitameOnlineResponse struct {
    quotes []Quote
}

type Quote struct {
    high             string
    open             string
    bid              string
    currencyPairCode string
    ask              string
    low              string
}

func sampleParse() {
    path := os.Getenv("PWD")
    bytes, err := ioutil.ReadFile(path + "/rate.json")
    if err != nil {
        log.Fatal(err)
    }
    var r GaitameOnlineResponse
    if err := json.Unmarshal(bytes, &r); err != nil {
        log.Fatal(err)
    }
    fmt.Println(r)
    // {[]} 
}

我不知道结果的原因。

我想使用json.Unmarshal在Go中解析此json。 {“ quotes”:[{“ high”:“ 1.9981”,“ open”:“ 1.9981”,“ bid”:“ 1.9981”,“ currencyPairCode”:...

json go unmarshalling
1个回答
0
投票

[有很多在线JSON验证器,例如https://jsonlint.com/

© www.soinside.com 2019 - 2024. All rights reserved.