在高隆有Ruby的awesome_print吗?
例如在红宝石你可以写:
require 'ap' x = {a:1,b:2} // also works for class ap x
输出将是:
{ "a" => 1,"b" => 2 }
最近我发现的是Printf(“%#v”,x)
如果您的目标是避免导入第三方软件包,则您的其他选项是使用
json.MarshalIndent:
x := map[string]interface{}{"a": 1,"b": 2} b,err := json.MarshalIndent(x,""," ") if err != nil { fmt.Println("error:",err) } fmt.Print(string(b))
输出:
{ "a": 1,"b": 2 }