Golang不正确的JSON解组

huangapple go评论75阅读模式
英文:

Golang improper JSON unmarshal

问题

为什么这段代码显示不正确的输出?

http://play.golang.org/p/NBYnJOhmV2

英文:

Why this code shows improper output

http://play.golang.org/p/NBYnJOhmV2

答案1

得分: 0

如果你想将JSON解析为一个结构体,那么结构体的成员必须是公开的,也就是说首字母必须大写。

例如:

type Base struct {
    Results []struct {
        Mp_id                   string
        First_name              string
        Last_name               string
    }
    Count int
    Page  struct {
        Count    int
        Per_page int
        Page     int
    }
}

Playground

英文:

If you want to parse JSON into a structure, the members must be public - ie have an initial Capital.

Eg

type Base struct {
	Results []struct {
		Mp_id                   string
		First_name              string
		Last_name               string
	}
	Count int
	Page  struct {
		Count    int
		Per_page int
		Page     int
	}
}

Playground

huangapple
  • 本文由 发表于 2014年10月9日 04:46:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/26266139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定