Created
August 1, 2016 16:42
-
-
Save scbizu/d6fab3a7a1840809ce183352f8cd4267 to your computer and use it in GitHub Desktop.
struct to json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
type JsonFor struct { | |
Foo string `json:"foo"` | |
Foo_s string `json:"foo_s,string"` | |
Foo_t string `json:"foo_t,omitempty"` | |
} | |
func main() { | |
var foo2 JsonFor | |
foo := &JsonFor{"a", "b", ""} | |
test, err := json.Marshal(foo) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(string(test)) | |
err = json.Unmarshal(test, &foo2) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(foo2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment