Skip to content

Commit

Permalink
增加屏幕输出实现
Browse files Browse the repository at this point in the history
  • Loading branch information
swxctx committed Dec 21, 2018
1 parent 5616f70 commit 30eb5ad
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package main

import (
"encoding/json"
"fmt"
"os"
"reflect"

"github.com/usthooz/oozlog/go"
)

// readJsonToFile 从文件中读取json信息
Expand All @@ -21,6 +25,37 @@ func readJsonToFile(fileName string) string {
break
}
json = `` + string(buf[:len]) + ``
ck := New("json2go", json)
ck.json2Struct()
}
return json
}

// json2Struct 完成json转换
func (xj *xjson) json2Struct() *xjson {
Xkeyv = Xkeyvori
if xj.JSONTag {
Xkeyv = Xkeyvtag
}
if err := json.Unmarshal([]byte(xj.Msg), &xj.Parent); err != nil {
ozlog.Errorf("parse json failed:", err)
return nil
}
xj.appendStr(fmt.Sprintf(Xbegin, xj.Name))
for k, v := range xj.Parent {
orik, k := xj.keyFilter(k)
tmptype := fmt.Sprintf(Xstr, reflect.TypeOf(v))
if tmptype == Xmap {
xj.subStruct(orik, v)
tmptype = k
}
if tmptype == Xlist {
xj.subList(orik, v)
tmptype = k
}
xj.appendStr(fmt.Sprintf(Xkeyv, k, tmptype, xj.MapTag[k]))
}
xj.printStruct()
xj.Flush()
return xj
}

0 comments on commit 30eb5ad

Please sign in to comment.