go的map[string]interface{}
阿新 • • 發佈:2018-12-10
func main() { json_str := `[{"id":3345195,"type":1,"txt":" "},{"id":3345234,"type":1,"txt":"sassa","file_ty":6,"music_vol":0,"bmt":0,"emt":0}]` var Ids []map[string]interface{} json.Unmarshal([]byte(json_str), &Ids) image_counts := len(Ids) videos := 0 subtitles := 0 //字幕數 decorates := 0 //含有貼紙的照片數 var is_has_video bool = false var is_has_subtitle bool = false _, _ = is_has_video, is_has_subtitle for i := 0; i < image_counts; i++ { data := Ids[i] key, exist := data["file_ty"] fmt.Println(key) if exist && key.(float64) == 6 { videos += 1 is_has_video = true } key, exist = data["txt"] if exist && strings.TrimSpace(key.(string)) != "" { subtitles += 1 is_has_subtitle = true } key, exist = data["decorate"] if exist && key.(string) != "" { decorates += 1 } } fmt.Println(videos, subtitles, decorates) }