• 类json格式字符串打印


    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
    }
  • 相关阅读:
    第四百六十九天 how can I 坚持
    第四百六十八天 how can I 坚持
    第四百四十六、七天 how can I 坚持
    第四百四十四、五天 how can I 坚持
    《Java练习题》Java进阶练习题(一)
    《Java练习题》Java习题集五
    《Java知识应用》Java加密方式(MD5)详解
    《Java知识应用》Java加密方式(Base64)详解
    《MySQL数据库》MySQL数据库安装(linux)
    《Java知识应用》Java Json说明和使用(fastjson)
  • 原文地址:https://www.cnblogs.com/zengyjun/p/10114692.html
Copyright © 2020-2023  润新知