zoukankan      html  css  js  c++  java
  • 类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
    }
  • 相关阅读:
    股指期货风声水起 股市"蛇人″给我们启示
    Goals of Distributed Application Design
    火箭股票,火箭发射(07.4.12)
    SQLAlchemy完全入门
    巧用异或
    FastAPI启用HTTPS
    错误记录:Can't connect to MySQL server on xxx
    MySQL常用命令
    就是想写点什么
    Android关于Activity class {package/class} does not exist
  • 原文地址:https://www.cnblogs.com/zengyjun/p/10114692.html
Copyright © 2011-2022 走看看