From 79a8faf49281e575548a121ef8d1f39e80b69ede Mon Sep 17 00:00:00 2001 From: swxctx Date: Thu, 20 Dec 2018 20:32:47 +0800 Subject: [PATCH] =?UTF-8?q?json=E8=BD=AC=E6=8D=A2=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=8F=8A=E6=96=87=E4=BB=B6=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- out.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 out.go diff --git a/out.go b/out.go new file mode 100644 index 0000000..1495c7b --- /dev/null +++ b/out.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + "os" +) + +func (xj *xjson) appendStr(kv string) { + xj.Out = append(xj.Out, kv) +} + +//output +func (xj *xjson) printStruct() { + for _, value := range xj.Sub { + for i := 0; i < len(value); i++ { + fmt.Println(value[i]) + } + } + + for i := 0; i < len(xj.Out); i++ { + fmt.Println(xj.Out[i]) + } +} + +//write struct to file +func (xj *xjson) writefileStruct(fileName string) { + file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) + file.WriteString(goBegin) + if err != nil { + fmt.Println("new file error...") + } + for _, value := range xj.Sub { + for i := 0; i < len(value); i++ { + if i == 0 || i == (len(value)-1) { + file.WriteString(value[i] + " " + "\n") + } else { + file.WriteString(" " + value[i] + " " + "\n") + } + } + } + + for i := 0; i < len(xj.Out); i++ { + if i == 0 || i == (len(xj.Out)-1) { + file.WriteString(xj.Out[i] + "\n") + } else { + file.WriteString(" " + xj.Out[i] + "\n") + } + } +}