Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1365)

Side by Side Diff: src/pkg/encoding/json/example_test.go

Issue 97840044: code review 97840044: encoding/json: add example for Indent, clarify the docs.
Patch Set: diff -r e3d533e55750 https://code.google.com/p/go/ Created 9 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pkg/encoding/json/indent.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package json_test 5 package json_test
6 6
7 import ( 7 import (
8 "bytes"
8 "encoding/json" 9 "encoding/json"
9 "fmt" 10 "fmt"
10 "io" 11 "io"
11 "log" 12 "log"
12 "os" 13 "os"
13 "strings" 14 "strings"
14 ) 15 )
15 16
16 func ExampleMarshal() { 17 func ExampleMarshal() {
17 type ColorGroup struct { 18 type ColorGroup struct {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 err := json.Unmarshal(c.Point, dst) 121 err := json.Unmarshal(c.Point, dst)
121 if err != nil { 122 if err != nil {
122 log.Fatalln("error:", err) 123 log.Fatalln("error:", err)
123 } 124 }
124 fmt.Println(c.Space, dst) 125 fmt.Println(c.Space, dst)
125 } 126 }
126 // Output: 127 // Output:
127 // YCbCr &{255 0 -10} 128 // YCbCr &{255 0 -10}
128 // RGB &{98 218 255} 129 // RGB &{98 218 255}
129 } 130 }
131
132 func ExampleIndent() {
133 type Road struct {
134 Name string
135 Number int
136 }
137 roads := []Road{
138 Road{"Diamond Fork", 29},
adg 2014/05/08 06:26:52 you can drop the "Road" on each of these lines
smcquay 2014/05/08 06:42:15 Done.
139 Road{"Sheep Creek", 51},
140 }
141
142 b, err := json.Marshal(roads)
143 if err != nil {
144 log.Fatal(err)
145 }
146
147 var out bytes.Buffer
148 json.Indent(&out, b, "=", "\t")
149 out.WriteTo(os.Stdout)
150 // Output:
151 // [
152 // = {
153 // = "Name": "Diamond Fork",
154 // = "Number": 29
155 // = },
156 // = {
157 // = "Name": "Sheep Creek",
158 // = "Number": 51
159 // = }
160 // =]
161 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/encoding/json/indent.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b