저는 응용 프로그램을 Go로 변환하는 새로운 사용자입니다.대문자없이 json 변수를 반환하십시오.
type Network struct {
Ssid string
Security string
Bitrate string
}
func Scan(w http.ResponseWriter, r *http.Request) {
output := runcmd(scripts+"scan.sh", true)
bytes := []byte(output)
var networks []Network
json.Unmarshal(bytes, &networks)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(networks)
}
문제는 반환 된 JSON 변수에 수도를 사용하지 않은 이전 버전입니다 : 내가 노력하고 다음과 같은 것을 가지고있다.
프런트 엔드에서 ssid
이 아닌 Ssid
을보고 싶습니다. 구조체의 속성을 소문자로 만들면 코드는 더 이상 unexported 변수가되므로 작동하지 않습니다.