Skip to content

Commit

Permalink
json转换屏幕输出及文件写入
Browse files Browse the repository at this point in the history
  • Loading branch information
swxctx committed Dec 20, 2018
1 parent d9f137f commit 79a8faf
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions out.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
}

0 comments on commit 79a8faf

Please sign in to comment.