私はnet/httpパッケージを使ってJsonデータをUrlで送信しますが、代わりに小文字キーを使用したいのですが、動作しません。ゴラン返信小文字jsonキー
この問題の例では、小文字の「カウント」と「データ」キーが必要です。
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type tableau struct {
Count int `json"count"`
Data []People `json"data"`
}
type People struct {
Id int `json"Id"`
Name string `json"Name"`
Age int `json"Age"`
}
func main() {
http.HandleFunc("/people", recupPeople)
fs := http.FileServer(http.Dir("Static"))
http.Handle("/", fs)
http.ListenAndServe(":80", nil)
}
func recupPeople(w http.ResponseWriter, r *http.Request) {
listPeople := &tableau{
Count: 4,
Data: []People{
People{Id: 1, Name: "Laurent", Age: 20},
People{Id: 2, Name: "Laurent", Age: 20},
},
}
peop, _ := json.Marshal(listPeople)
fmt.Println(string(peop))
w.Write(peop)
json.NewEncoder(w).Encode(listPeople)
}
しかし、私はURLをチェックするとき、私は小文字を持っていませんでした。
真心を込め、 ローラン
あなたのタグが不正です: '\' JSON: "カウント" \ '' – JimB