package main import ( "fmt" ) func main() { msg := "{Amount:21111111 DrawalBankHolder:刘成友 DrawalBankNo:6212264100011335366 DrawalSn:5112118111111690 DrawalTime:2018-11-30T00:00:00+08:00 FineAmt:15452 Interest:612977 IsCompensation:TRUE LoanOvdRate:1.111751 LoanRate:18.11 LoanTerm:3 LoanTermUnit:M PlanList:[{FineAmt:200 Interest:100 InterestPenalty:40 IsCompensation:TRUE Principal:400 PrincipalPenalty:160 RepaidFineAmt:200 RepaidInterest:200 RepaidInterestPenalty:58 RepaidPrincipal:500 RepaidPrincipalPenalty:142 BillStatus:CLEAR TermEndDate:2018-11-30T00:00:00+08:00 TermNo:1 TermStartDate:2018-11-30T00:00:00+08:00} {FineAmt:100 Interest:211485 InterestPenalty:0 IsCompensation:FALSE Principal:6666174 PrincipalPenalty:0 RepaidFineAmt:100 RepaidInterest:100 RepaidInterestPenalty:0 RepaidPrincipal:100 RepaidPrincipalPenalty:0 BillStatus:NORMAL TermEndDate:2018-12-30T00:00:00+08:00 TermNo:2 TermStartDate:2018-12-11T00:00:00+08:00} {FineAmt:100 Interest:111492 InterestPenalty:0 IsCompensation:FALSE Principal:6766167 PrincipalPenalty:0 RepaidFineAmt:100 RepaidInterest:100 RepaidInterestPenalty:0 RepaidPrincipal:100 RepaidPrincipalPenalty:0 BillStatus:NORMAL TermEndDate:2019-11-30T00:00:00+08:00 TermNo:3 TermStartDate:2019-11-11T00:00:00+08:00}] Principal:21111111 RepaidInterest:100 RepaidList:[{RepaidInterest:100 RepaidInterestPenalty:20 RepaidPrincipal:400 RepaidPrincipalPenalty:80 RepaidSn:111 RepaidType:OFFLINE RepayConfirmDate:2018-11-30T22:22:22+08:00 TermNo:1}] RepaidPrincipal:100 RepaidTotal:100 RepaidFineAmt:200 BillStatus:OVD}" printMsg(msg) } func printMsg(msg string) { blankNum := 0 for _, value := range msg { cc := fmt.Sprintf("%c", value) switch cc { case "{": fmt.Printf("{") fmt.Printf(" ") blankNum += 4 fmt.Printf(getBlank(blankNum)) case "}": fmt.Printf(" ") blankNum -= 4 fmt.Printf(getBlank(blankNum)) fmt.Printf("}") case "[": fmt.Printf("[") fmt.Printf(" ") blankNum += 4 fmt.Printf(getBlank(blankNum)) case "]": fmt.Printf(" ") blankNum -= 4 fmt.Printf(getBlank(blankNum)) fmt.Printf("]") case " ": fmt.Printf(" ") fmt.Printf(getBlank(blankNum)) default: fmt.Printf(cc) } } } func getBlank(num int) string { blanks := "" for i := 0; i < num; i++ { blanks += " " } return blanks }