Last active
          September 27, 2016 08:20 
        
      - 
      
- 
        Save syfun/08ea4cf4b15830bff2adda164d4c5372 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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" | |
| "log" | |
| ) | |
| // Person ... | |
| type Person struct { | |
| Name string `json:"name"` | |
| age int | |
| } | |
| func main() { | |
| person := Person{"Jack", 29} | |
| b, err := json.Marshal(&person) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| fmt.Println(string(b)) | |
| // {"name":"Jack"} | |
| // json包只处理导出的字段类型,也就是struct中大写的字段 | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment