mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: update documentation for MarshalIndent
Make arguments semantics clear without the need to look for json.Indent documentation. Change-Id: If9adfe9f477a30d426ae83790b0f2578c0a809b7 Reviewed-on: https://go-review.googlesource.com/61670 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
80b2ae5878
commit
b86fae041b
2 changed files with 21 additions and 0 deletions
|
|
@ -273,3 +273,22 @@ func ExampleIndent() {
|
|||
// = }
|
||||
// =]
|
||||
}
|
||||
|
||||
func ExampleMarshalIndent() {
|
||||
data := map[string]int{
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
}
|
||||
|
||||
json, err := json.MarshalIndent(data, "<prefix>", "<indent>")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(json))
|
||||
// Output:
|
||||
// {
|
||||
// <prefix><indent>"a": 1,
|
||||
// <prefix><indent>"b": 2
|
||||
// <prefix>}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue