我想在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验证器,例如https://jsonlint.com/