的阵列我想创建GatewayInfo
的JSON其中类型被这样定义:Golang和JSON结构
var gatewayInfo = make(GatewayInfo, nb_spans)
到:
type SpanInfo struct {
imsi string
network string
network_status string
signal_quality int
slot int
state string
}
type GatewayInfo []SpanInfo
网关信息与创建创建JSON,我用json.Marshal
函数:
gatewayInfo := getGatewayInfo(spans)
log.Printf("Polling content: %s\n", gatewayInfo)
jsonInfo, _ := json.Marshal(gatewayInfo)
log.Printf("jsonInfo: %s\n", jsonInfo)
Unfortuna tely结果不是我所期待的:
2015/02/09 13:48:26 Polling content: [{652020105829193 20801 Registered (Roaming) %!s(int=17) %!s(int=2) } {652020105829194 20801 Registered (Roaming) %!s(int=16) %!s(int=3) } {652020105829192 20801 Registered (Roaming) %!s(int=19) %!s(int=1) } {652020105829197 20801 Registered (Roaming) %!s(int=19) %!s(int=4) }]
2015/02/09 13:48:26 jsonInfo: [{},{},{},{}]
正如我们所看到的,GatewayInfo
实例具有SpanInfo
,但在JSON我有空SpanInfo
。
可能重复( http://stackoverflow.com/questions/15452004/my-structures-are-not-marshalling-into-json) – 2015-02-09 14:19:07