1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| import ( "encoding/json" "fmt" )
type Article struct { ArticleId int `json:"article_id"` UserId int `json:"user_id"` CategoryId int `json:"category_id"` TagIds []int `json:"tag_ids"` LinkUrl string `json:"link_url"` CoverImage string `json:"cover_image"` Title string `json:"title"` BriefContent string `json:"brief_content"` IsEnglish int `json:"is_english"` IsOriginal int `json:"is_original"` Content string `json:"content"` Ctime int `json:"ctime"` Mtime int `json:"mtime"` Rtime int `json:"rtime"` ViewCount int `json:"view_count"` CollectCount int `json:"collect_count"` DiggCount int `json:"digg_count"` CommentCount int `json:"comment_count"` Status int `json:"status"` }
func main() { article := &Article{ ArticleId: 6931630572720619534, UserId: 465848661970824, CategoryId: 6809637769959178254, TagIds: []int{6809640445233070094}, LinkUrl: "", CoverImage: "", Title: "spring中那些让你爱不释手的代码技巧", BriefContent: "最近越来越多的读者认可我的文章,还是件挺让人高兴的事情。有些读者私信我说希望后面多分享spring方面的文章,这样能够在实际工作中派上用场。正好我对spring源码有过一定的研究,并结合我这几年实际的工作经验,把spring中我认为不错的知识点总结一下,希望对您有所帮助。 实现…", IsEnglish: 0, IsOriginal: 1, Content: "", Ctime: 1613896165, Mtime: 1625579546, Rtime: 1613994419, ViewCount: 10374, CollectCount: 533, DiggCount: 339, CommentCount: 22, Status: 2, } str, _ := json.Marshal(article) fmt.Println(string(str)) article2 := &Article{} _ = json.Unmarshal(str, article2) fmt.Println(article2) }
|