我正在尝试将 JSON http 响应解组到我创建的 Struct 中。
来自 API 端点的 JSON:
[{"Created_Datetime":"2\/16\/2013 2:57:59 AM",
"Last_Login_Datetime":"11\/27\/2013 11:00:49 PM",
"Leaves":0,
"Level":18,
"Losses":47,
"MasteryLevel":2,
"Name":"sergiotapia",
"Rank_Confidence":0,
"Rank_Stat":0,
"TeamId":121147,
"Team_Name":"sergiosteam",
"Wins":65,
"ret_msg":null}]
我的结构:
type Player struct {
Created_datetime string
Last_login_datetime string
Leaves int
Level int
Losses int
Mastery_level int // This is the one that isn't being updated with the value.
Name string
Rank_confidence int
Rank_stat float32
Team_id int
Team_name string
Wins int
Ret_msg string
}
这是我解组的方式:
var players []Player // Using an array because the API returns a JSON array - always.
json.Unmarshal(httpResponse, &players)
return players[0]
导致:
// fmt.Println(player)
{2/16/2013 2:57:59 AM 11/27/2013 11:00:49 PM 0 18 47 0 sergiotapia 0 0 0 sergiosteam 65 }
为什么我的 struct 对象中没有更新 MasterLevel 的值?
在这里去游乐场:http : //play.golang.org/p/LPNiQDPx2E
相关分类