我在读取 json 数组时遇到了一个问题。需要以下查询的帮助。
请求 Json :
{ "httpReq": {
"username": "1234567890",
"password": "1234567890",
"number": "123456"
}
}
响应 JSON :
{ "httpResp": {
"status": "Pass",
"message": "great"
}
}
下面是我的代码:如果我在其工作下传递 json 对象,但我需要在 json 中发送“httpReq”。
package main
import (
"encoding/json"
"fmt"
)
type people struct {
Username string `json:"username"`
Password string `json:"password"`
Number string `json:"number"`
}
type peopleread struct {
Collection []people
}
func main() {
text := `{
"username": "1234567890",
"password": "1234567890",
"number": "123456"
}`
textBytes := []byte(text)
//people1 := people{}
var people2 people
err := json.Unmarshal(textBytes, &people2)
if err != nil {
fmt.Println(err)
return
}
Username := people2.Username
Password := people2.Password
Number := people2.Number
fmt.Println(Username)
fmt.Println(Password)
fmt.Println(Number)
}
幕布斯7119047
相关分类