Go编程语言:JSON编组

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

go programming language: json marshalling

问题

我期望从以下代码中得到{ "a": "42", "b": "78"},但实际上并没有得到。

package main

import (
    "encoding/json"
    "fmt"
)

type S struct {
    A int  `json:"a,string"`
    B *int `json:"b,string"`
}

func main() {
    var s S
    json.Unmarshal([]byte(`{"a":"42","b":"78"}`), &s)
    m, _ := json.Marshal(s)
    fmt.Println(string(m))
}

我做错了什么吗?

英文:

I'm expecting {"a":"42","b":"78"} from the following code, but it doesn't do it.

package main

import (
 "encoding/json"
 "fmt"
)

type S struct {
 A int  `json:"a,string"`
 B *int `json:"b,string"`
}

func main() {
 var s S
 json.Unmarshal([]byte(`{"a":"42","b":"78"}`), &s)
 m, _ := json.Marshal(s)
 fmt.Println(string(m))
}

Am I doing something wrong?

答案1

得分: 3

这是 Go 语言 1.3 版本的已知问题。

请参考 https://code.google.com/p/go/issues/detail?id=8587

英文:

This is a known issue with 1.3 of the go language.

see https://code.google.com/p/go/issues/detail?id=8587

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

发表评论

匿名网友

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

确定