ToFile 注意传入的不是指针
(srcJsonFileFPath string, input interface{})
| 9 | |
| 10 | // ToFile 注意传入的不是指针 |
| 11 | func ToFile(srcJsonFileFPath string, input interface{}) error { |
| 12 | jsonBytes, err := json.Marshal(input) |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | |
| 17 | file, err := os.Create(filepath.FromSlash(srcJsonFileFPath)) |
| 18 | if err != nil { |
| 19 | return err |
| 20 | } |
| 21 | defer func() { |
| 22 | _ = file.Close() |
| 23 | }() |
| 24 | |
| 25 | _, err = file.Write(jsonBytes) |
| 26 | if err != nil { |
| 27 | return err |
| 28 | } |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | // ToStruct 传入的必须是指针 |
| 33 | func ToStruct(desJsonFileFPath string, output interface{}) error { |