如{"SessionId":"12345","Op":"werdfsdde22233","appId":"654343dfddd33424dd","Online":false},
{"SessionId":"234567","Op":"dwqdqw","appId":"ddd445454545455454","Online":true},
{"SessionId":"8903283","Op":"ddddddddddddd","appId":"78v7f89ddfhujjjkhj","Online":false}` 这个json串如何转换成 三个struct 谢谢
使用encoding包中json文件中的marshal和unmarshal函数来序列化和反序列化即可。举例:
var user *User
err = json.Unmarshal([]byte(jsonStr), user)
if err != nil {
fmt.Println("反序列化出错,info:", err)
}else{
fmt.Println("用户名:%s",user.UserName)
}
温馨提示:答案为网友推荐,仅供参考