最近发现用json.MarshalIndent()转出来的json打印出来比较好看
比如
```
js,_ := json.Marshal(&person)
jsIndent,_ := json.MarshalIndent(&person, "", "\t")
fmt.Println("\njs:\n",string(js), "\n\njsIndent:\n",string(jsIndent)
```
打印出来:
```
js:
{"Time":1987,"Name":"liangyongxing","Age":12}
jsIndent:
{
"Time": 1987,
"Name": "liangyongxing",
"Age": 12
}
```
但是我不是很清楚,
#####**1.这个是只影响打印吗? 在数据实际传递过程和普通的Marshal有没有区别?**
#####**2.MarshalIndent还可以设置前缀不为空**, 比如
```jsIndent,_ := json.MarshalIndent(&person, "haha", "\t")```
就变成
```
jsIndent:
{
haha "Time": 1987,
haha "Name": "liangyongxing",
haha "Age": 12
haha}```
然后这个json传递出去就带着这个前缀吗?
有疑问加站长微信联系(非本文作者)