文件保存内容(whitelist.csv):
{
"a": true,
"b": true,
"c": true,
"d": true,
"e": true
}
处理代码(main.go):
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
func main() {
b, err := ioutil.ReadFile("C:\\Users\\admin2\\Desktop\\whitelist.csv")
if err != nil {
fmt.Print(err)
}
whitelist := map[string]bool{}
err = json.Unmarshal([]byte(string(b)), &whitelist)
if err != nil {
panic(err)
}
for key, value := range whitelist {
fmt.Println("key", key, "value", value)
fmt.Printf("%T", value)
}
}
有疑问加站长微信联系(非本文作者)