Created
March 8, 2018 16:44
-
-
Save s4l1h/42973b92c79277078fec7cc736ae2bbd to your computer and use it in GitHub Desktop.
Golang JSON ve interface kullanımı.(v1)
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" | |
) | |
// Person object | |
type Person struct { | |
FirstName, LastName string // Küçük harf olursa json kütüphanesi erişemeyecek. | |
Number string `json:"number"` // json field name'i değişebiliriz. | |
} | |
func main() { | |
p := &Person{ | |
FirstName: "A.Kadir", | |
LastName: "Mutlu", | |
} | |
p.Number = "0449444944944" | |
result, err := json.Marshal(p) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(string(result)) | |
/* | |
{ | |
"FirstName":"A.Kadir", | |
"LastName":"Mutlu", | |
"number":"0449444944944" | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment