Regnerate

This commit is contained in:
Mark McGranaghan 2019-09-01 16:20:57 -07:00
parent 738d92e305
commit a0ac6165dd
3 changed files with 20 additions and 6 deletions
examples/json
public

@ -14,7 +14,8 @@ type response1 struct {
Page int
Fruits []string
}
// Only exported fields will be encoded/decoded in JSON.
// Only exported fields will be encoded/decoded in JSON.
// Fields must start with capital letters to be exported.
type response2 struct {
Page int `json:"page"`

@ -1,2 +1,2 @@
d4dc2281f64061f077d8f1e9687538f41a339b25
xC6SHbzGBZC
6b92694b7be60cdec3e7a04e9fdbf49d5c84adb1
63PdbTHxKJA

19
public/json generated

@ -43,7 +43,7 @@ data types.</p>
</td>
<td class="code leading">
<a href="http://play.golang.org/p/xC6SHbzGBZC"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<a href="http://play.golang.org/p/63PdbTHxKJA"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
</pre></div>
@ -76,7 +76,20 @@ decoding of custom types below.</p>
<span class="nx">Page</span> <span class="kt">int</span>
<span class="nx">Fruits</span> <span class="p">[]</span><span class="kt">string</span>
<span class="p">}</span>
<span class="kd">type</span> <span class="nx">response2</span> <span class="kd">struct</span> <span class="p">{</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<p>Only exported fields will be encoded/decoded in JSON.
Fields must start with capital letters to be exported.</p>
</td>
<td class="code leading">
<div class="highlight"><pre><span class="kd">type</span> <span class="nx">response2</span> <span class="kd">struct</span> <span class="p">{</span>
<span class="nx">Page</span> <span class="kt">int</span> <span class="s">`json:&quot;page&quot;`</span>
<span class="nx">Fruits</span> <span class="p">[]</span><span class="kt">string</span> <span class="s">`json:&quot;fruits&quot;`</span>
<span class="p">}</span>
@ -401,7 +414,7 @@ for more.</p>
</div>
<script>
var codeLines = [];
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"encoding/json\"\u000Aimport \"fmt\"\u000Aimport \"os\"\u000A');codeLines.push('type response1 struct {\u000A Page int\u000A Fruits []string\u000A}\u000Atype response2 struct {\u000A Page int `json:\"page\"`\u000A Fruits []string `json:\"fruits\"`\u000A}\u000A');codeLines.push('func main() {\u000A');codeLines.push(' bolB, _ := json.Marshal(true)\u000A fmt.Println(string(bolB))\u000A');codeLines.push(' intB, _ := json.Marshal(1)\u000A fmt.Println(string(intB))\u000A');codeLines.push(' fltB, _ := json.Marshal(2.34)\u000A fmt.Println(string(fltB))\u000A');codeLines.push(' strB, _ := json.Marshal(\"gopher\")\u000A fmt.Println(string(strB))\u000A');codeLines.push(' slcD := []string{\"apple\", \"peach\", \"pear\"}\u000A slcB, _ := json.Marshal(slcD)\u000A fmt.Println(string(slcB))\u000A');codeLines.push(' mapD := map[string]int{\"apple\": 5, \"lettuce\": 7}\u000A mapB, _ := json.Marshal(mapD)\u000A fmt.Println(string(mapB))\u000A');codeLines.push(' res1D := &response1{\u000A Page: 1,\u000A Fruits: []string{\"apple\", \"peach\", \"pear\"}}\u000A res1B, _ := json.Marshal(res1D)\u000A fmt.Println(string(res1B))\u000A');codeLines.push(' res2D := &response2{\u000A Page: 1,\u000A Fruits: []string{\"apple\", \"peach\", \"pear\"}}\u000A res2B, _ := json.Marshal(res2D)\u000A fmt.Println(string(res2B))\u000A');codeLines.push(' byt := []byte(`{\"num\":6.13,\"strs\":[\"a\",\"b\"]}`)\u000A');codeLines.push(' var dat map[string]interface{}\u000A');codeLines.push(' if err := json.Unmarshal(byt, &dat); err != nil {\u000A panic(err)\u000A }\u000A fmt.Println(dat)\u000A');codeLines.push(' num := dat[\"num\"].(float64)\u000A fmt.Println(num)\u000A');codeLines.push(' strs := dat[\"strs\"].([]interface{})\u000A str1 := strs[0].(string)\u000A fmt.Println(str1)\u000A');codeLines.push(' str := `{\"page\": 1, \"fruits\": [\"apple\", \"peach\"]}`\u000A res := response2{}\u000A json.Unmarshal([]byte(str), &res)\u000A fmt.Println(res)\u000A fmt.Println(res.Fruits[0])\u000A');codeLines.push(' enc := json.NewEncoder(os.Stdout)\u000A d := map[string]int{\"apple\": 5, \"lettuce\": 7}\u000A enc.Encode(d)\u000A}\u000A');codeLines.push('');codeLines.push('');
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"encoding/json\"\u000Aimport \"fmt\"\u000Aimport \"os\"\u000A');codeLines.push('type response1 struct {\u000A Page int\u000A Fruits []string\u000A}\u000A');codeLines.push('type response2 struct {\u000A Page int `json:\"page\"`\u000A Fruits []string `json:\"fruits\"`\u000A}\u000A');codeLines.push('func main() {\u000A');codeLines.push(' bolB, _ := json.Marshal(true)\u000A fmt.Println(string(bolB))\u000A');codeLines.push(' intB, _ := json.Marshal(1)\u000A fmt.Println(string(intB))\u000A');codeLines.push(' fltB, _ := json.Marshal(2.34)\u000A fmt.Println(string(fltB))\u000A');codeLines.push(' strB, _ := json.Marshal(\"gopher\")\u000A fmt.Println(string(strB))\u000A');codeLines.push(' slcD := []string{\"apple\", \"peach\", \"pear\"}\u000A slcB, _ := json.Marshal(slcD)\u000A fmt.Println(string(slcB))\u000A');codeLines.push(' mapD := map[string]int{\"apple\": 5, \"lettuce\": 7}\u000A mapB, _ := json.Marshal(mapD)\u000A fmt.Println(string(mapB))\u000A');codeLines.push(' res1D := &response1{\u000A Page: 1,\u000A Fruits: []string{\"apple\", \"peach\", \"pear\"}}\u000A res1B, _ := json.Marshal(res1D)\u000A fmt.Println(string(res1B))\u000A');codeLines.push(' res2D := &response2{\u000A Page: 1,\u000A Fruits: []string{\"apple\", \"peach\", \"pear\"}}\u000A res2B, _ := json.Marshal(res2D)\u000A fmt.Println(string(res2B))\u000A');codeLines.push(' byt := []byte(`{\"num\":6.13,\"strs\":[\"a\",\"b\"]}`)\u000A');codeLines.push(' var dat map[string]interface{}\u000A');codeLines.push(' if err := json.Unmarshal(byt, &dat); err != nil {\u000A panic(err)\u000A }\u000A fmt.Println(dat)\u000A');codeLines.push(' num := dat[\"num\"].(float64)\u000A fmt.Println(num)\u000A');codeLines.push(' strs := dat[\"strs\"].([]interface{})\u000A str1 := strs[0].(string)\u000A fmt.Println(str1)\u000A');codeLines.push(' str := `{\"page\": 1, \"fruits\": [\"apple\", \"peach\"]}`\u000A res := response2{}\u000A json.Unmarshal([]byte(str), &res)\u000A fmt.Println(res)\u000A fmt.Println(res.Fruits[0])\u000A');codeLines.push(' enc := json.NewEncoder(os.Stdout)\u000A d := map[string]int{\"apple\": 5, \"lettuce\": 7}\u000A enc.Encode(d)\u000A}\u000A');codeLines.push('');codeLines.push('');
</script>
<script src="site.js" async></script>
</body>