feat(Go-Tool): 增加读取json文件方法及其单测类
This commit is contained in:
@@ -8,6 +8,7 @@ package file
|
||||
|
||||
import (
|
||||
"Go-Tool/util/file"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
@@ -19,3 +20,60 @@ func TestReadFileLineNum(t *testing.T) {
|
||||
func TestReadFileLineNumExceptEmptyLine(t *testing.T) {
|
||||
fmt.Println(file.ReadFileLineNumExceptEmptyLine("F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\1\\11.txt"))
|
||||
}
|
||||
|
||||
func TestReadJsonFile(t *testing.T) {
|
||||
content, _ := file.ReadJsonFile("F:\\Go个人代码\\src\\Go-Tool\\test\\file\\json_file_test_mode.json")
|
||||
fmt.Println(content)
|
||||
var testMode JsonTestMode
|
||||
_ = json.Unmarshal([]byte(content), &testMode)
|
||||
for _, r := range testMode.RareNumAward {
|
||||
fmt.Println(r.Num)
|
||||
fmt.Println()
|
||||
for _, r1 := range r.Award {
|
||||
fmt.Println(fmt.Sprintf("%d %d", r1[0], r1[1]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//被读取Json文件的测试结构体
|
||||
type JsonTestMode struct {
|
||||
CandleLightingReward CandleLightingReward
|
||||
|
||||
Cake []Cake
|
||||
|
||||
RareNumAward []RareNumAward
|
||||
|
||||
CommonNumAward [][]int
|
||||
|
||||
DailyAwardPool [][]int
|
||||
|
||||
DailyExtraction []DailyExtraction
|
||||
|
||||
FinalAward [][]int
|
||||
|
||||
CandleNumStart int
|
||||
|
||||
CandleNumInterval int
|
||||
|
||||
DiamondNum int
|
||||
|
||||
ThemeId int
|
||||
}
|
||||
|
||||
type CandleLightingReward struct {
|
||||
Num int
|
||||
AwardPool [][]int
|
||||
}
|
||||
type Cake struct {
|
||||
Level int
|
||||
CandleNum int
|
||||
Award [][]int
|
||||
}
|
||||
type RareNumAward struct {
|
||||
Num int
|
||||
Award [][]int
|
||||
}
|
||||
type DailyExtraction struct {
|
||||
Day int
|
||||
Num int
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user