gopl-zh.github.com/ch4/ch4-05.html

2275 lines
84 KiB
HTML
Raw Normal View History

2015-12-09 07:57:17 +00:00
<!DOCTYPE HTML>
<html lang="zh-tw" >
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
2015-12-31 08:20:27 +00:00
<title>JSON | Go语言圣经</title>
2015-12-09 07:57:17 +00:00
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="">
<meta name="generator" content="GitBook 2.5.2">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="../gitbook/style.css">
2015-12-28 08:08:26 +00:00
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-katex/katex.min.css">
2015-12-09 07:57:17 +00:00
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
<link rel="next" href="../ch4/ch4-06.html" />
<link rel="prev" href="../ch4/ch4-04.html" />
</head>
<body>
2015-12-31 08:20:27 +00:00
<div class="book" data-level="4.5" data-chapter-title="JSON" data-filepath="ch4/ch4-05.md" data-basepath=".." data-revision="Thu Dec 31 2015 16:18:40 GMT+0800 (中国标准时间)">
2015-12-09 07:57:17 +00:00
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="0" data-path="index.html">
<a href="../index.html">
<i class="fa fa-check"></i>
前言
</a>
<ul class="articles">
<li class="chapter " data-level="0.1" data-path="ch0/ch0-01.html">
<a href="../ch0/ch0-01.html">
<i class="fa fa-check"></i>
<b>0.1.</b>
Go語言起源
</a>
</li>
<li class="chapter " data-level="0.2" data-path="ch0/ch0-02.html">
<a href="../ch0/ch0-02.html">
<i class="fa fa-check"></i>
<b>0.2.</b>
Go語言項目
</a>
</li>
<li class="chapter " data-level="0.3" data-path="ch0/ch0-03.html">
<a href="../ch0/ch0-03.html">
<i class="fa fa-check"></i>
<b>0.3.</b>
本書的組織
</a>
</li>
<li class="chapter " data-level="0.4" data-path="ch0/ch0-04.html">
<a href="../ch0/ch0-04.html">
<i class="fa fa-check"></i>
<b>0.4.</b>
更多的信息
</a>
</li>
<li class="chapter " data-level="0.5" data-path="ch0/ch0-05.html">
<a href="../ch0/ch0-05.html">
<i class="fa fa-check"></i>
<b>0.5.</b>
2015-12-21 04:55:18 +00:00
致謝
2015-12-09 07:57:17 +00:00
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1" data-path="ch1/ch1.html">
<a href="../ch1/ch1.html">
<i class="fa fa-check"></i>
<b>1.</b>
入門
</a>
<ul class="articles">
<li class="chapter " data-level="1.1" data-path="ch1/ch1-01.html">
<a href="../ch1/ch1-01.html">
<i class="fa fa-check"></i>
<b>1.1.</b>
Hello, World
</a>
</li>
<li class="chapter " data-level="1.2" data-path="ch1/ch1-02.html">
<a href="../ch1/ch1-02.html">
<i class="fa fa-check"></i>
<b>1.2.</b>
命令行參數
</a>
</li>
<li class="chapter " data-level="1.3" data-path="ch1/ch1-03.html">
<a href="../ch1/ch1-03.html">
<i class="fa fa-check"></i>
<b>1.3.</b>
2015-12-21 04:55:18 +00:00
査找重複的行
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="1.4" data-path="ch1/ch1-04.html">
<a href="../ch1/ch1-04.html">
<i class="fa fa-check"></i>
<b>1.4.</b>
2015-12-21 04:55:18 +00:00
GIF動畵
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="1.5" data-path="ch1/ch1-05.html">
<a href="../ch1/ch1-05.html">
<i class="fa fa-check"></i>
<b>1.5.</b>
2015-12-28 08:08:26 +00:00
獲取URL
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="1.6" data-path="ch1/ch1-06.html">
<a href="../ch1/ch1-06.html">
<i class="fa fa-check"></i>
<b>1.6.</b>
2015-12-28 08:08:26 +00:00
併發獲取多個URL
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="1.7" data-path="ch1/ch1-07.html">
<a href="../ch1/ch1-07.html">
<i class="fa fa-check"></i>
<b>1.7.</b>
Web服務
</a>
</li>
<li class="chapter " data-level="1.8" data-path="ch1/ch1-08.html">
<a href="../ch1/ch1-08.html">
<i class="fa fa-check"></i>
<b>1.8.</b>
本章要點
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2" data-path="ch2/ch2.html">
<a href="../ch2/ch2.html">
<i class="fa fa-check"></i>
<b>2.</b>
程序結構
</a>
<ul class="articles">
<li class="chapter " data-level="2.1" data-path="ch2/ch2-01.html">
<a href="../ch2/ch2-01.html">
<i class="fa fa-check"></i>
<b>2.1.</b>
命名
</a>
</li>
<li class="chapter " data-level="2.2" data-path="ch2/ch2-02.html">
<a href="../ch2/ch2-02.html">
<i class="fa fa-check"></i>
<b>2.2.</b>
聲明
</a>
</li>
<li class="chapter " data-level="2.3" data-path="ch2/ch2-03.html">
<a href="../ch2/ch2-03.html">
<i class="fa fa-check"></i>
<b>2.3.</b>
變量
</a>
</li>
<li class="chapter " data-level="2.4" data-path="ch2/ch2-04.html">
<a href="../ch2/ch2-04.html">
<i class="fa fa-check"></i>
<b>2.4.</b>
賦值
</a>
</li>
<li class="chapter " data-level="2.5" data-path="ch2/ch2-05.html">
<a href="../ch2/ch2-05.html">
<i class="fa fa-check"></i>
<b>2.5.</b>
類型
</a>
</li>
<li class="chapter " data-level="2.6" data-path="ch2/ch2-06.html">
<a href="../ch2/ch2-06.html">
<i class="fa fa-check"></i>
<b>2.6.</b>
包和文件
</a>
</li>
<li class="chapter " data-level="2.7" data-path="ch2/ch2-07.html">
<a href="../ch2/ch2-07.html">
<i class="fa fa-check"></i>
<b>2.7.</b>
作用域
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="3" data-path="ch3/ch3.html">
<a href="../ch3/ch3.html">
<i class="fa fa-check"></i>
<b>3.</b>
基礎數據類型
</a>
<ul class="articles">
<li class="chapter " data-level="3.1" data-path="ch3/ch3-01.html">
<a href="../ch3/ch3-01.html">
<i class="fa fa-check"></i>
<b>3.1.</b>
整型
</a>
</li>
<li class="chapter " data-level="3.2" data-path="ch3/ch3-02.html">
<a href="../ch3/ch3-02.html">
<i class="fa fa-check"></i>
<b>3.2.</b>
浮點數
</a>
</li>
<li class="chapter " data-level="3.3" data-path="ch3/ch3-03.html">
<a href="../ch3/ch3-03.html">
<i class="fa fa-check"></i>
<b>3.3.</b>
2015-12-21 04:55:18 +00:00
複數
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="3.4" data-path="ch3/ch3-04.html">
<a href="../ch3/ch3-04.html">
<i class="fa fa-check"></i>
<b>3.4.</b>
2015-12-21 04:55:18 +00:00
布爾型
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="3.5" data-path="ch3/ch3-05.html">
<a href="../ch3/ch3-05.html">
<i class="fa fa-check"></i>
<b>3.5.</b>
字符串
</a>
</li>
<li class="chapter " data-level="3.6" data-path="ch3/ch3-06.html">
<a href="../ch3/ch3-06.html">
<i class="fa fa-check"></i>
<b>3.6.</b>
常量
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="4" data-path="ch4/ch4.html">
<a href="../ch4/ch4.html">
<i class="fa fa-check"></i>
<b>4.</b>
2015-12-21 04:55:18 +00:00
複合數據類型
2015-12-09 07:57:17 +00:00
</a>
<ul class="articles">
<li class="chapter " data-level="4.1" data-path="ch4/ch4-01.html">
<a href="../ch4/ch4-01.html">
<i class="fa fa-check"></i>
<b>4.1.</b>
數組
</a>
</li>
<li class="chapter " data-level="4.2" data-path="ch4/ch4-02.html">
<a href="../ch4/ch4-02.html">
<i class="fa fa-check"></i>
<b>4.2.</b>
2015-12-31 08:20:27 +00:00
Slice
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="4.3" data-path="ch4/ch4-03.html">
<a href="../ch4/ch4-03.html">
<i class="fa fa-check"></i>
<b>4.3.</b>
2015-12-31 08:20:27 +00:00
Map
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="4.4" data-path="ch4/ch4-04.html">
<a href="../ch4/ch4-04.html">
<i class="fa fa-check"></i>
<b>4.4.</b>
結構體
</a>
</li>
<li class="chapter active" data-level="4.5" data-path="ch4/ch4-05.html">
<a href="../ch4/ch4-05.html">
<i class="fa fa-check"></i>
<b>4.5.</b>
JSON
</a>
</li>
<li class="chapter " data-level="4.6" data-path="ch4/ch4-06.html">
<a href="../ch4/ch4-06.html">
<i class="fa fa-check"></i>
<b>4.6.</b>
文本和HTML模闆
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="5" data-path="ch5/ch5.html">
<a href="../ch5/ch5.html">
<i class="fa fa-check"></i>
<b>5.</b>
函數
</a>
<ul class="articles">
<li class="chapter " data-level="5.1" data-path="ch5/ch5-01.html">
<a href="../ch5/ch5-01.html">
<i class="fa fa-check"></i>
<b>5.1.</b>
函數聲明
</a>
</li>
<li class="chapter " data-level="5.2" data-path="ch5/ch5-02.html">
<a href="../ch5/ch5-02.html">
<i class="fa fa-check"></i>
<b>5.2.</b>
遞歸
</a>
</li>
<li class="chapter " data-level="5.3" data-path="ch5/ch5-03.html">
<a href="../ch5/ch5-03.html">
<i class="fa fa-check"></i>
<b>5.3.</b>
多返迴值
</a>
</li>
<li class="chapter " data-level="5.4" data-path="ch5/ch5-04.html">
<a href="../ch5/ch5-04.html">
<i class="fa fa-check"></i>
<b>5.4.</b>
錯誤
</a>
</li>
<li class="chapter " data-level="5.5" data-path="ch5/ch5-05.html">
<a href="../ch5/ch5-05.html">
<i class="fa fa-check"></i>
<b>5.5.</b>
函數值
</a>
</li>
<li class="chapter " data-level="5.6" data-path="ch5/ch5-06.html">
<a href="../ch5/ch5-06.html">
<i class="fa fa-check"></i>
<b>5.6.</b>
匿名函數
</a>
</li>
<li class="chapter " data-level="5.7" data-path="ch5/ch5-07.html">
<a href="../ch5/ch5-07.html">
<i class="fa fa-check"></i>
<b>5.7.</b>
可變參數
</a>
</li>
<li class="chapter " data-level="5.8" data-path="ch5/ch5-08.html">
<a href="../ch5/ch5-08.html">
<i class="fa fa-check"></i>
<b>5.8.</b>
Deferred函數
</a>
</li>
<li class="chapter " data-level="5.9" data-path="ch5/ch5-09.html">
<a href="../ch5/ch5-09.html">
<i class="fa fa-check"></i>
<b>5.9.</b>
Panic異常
</a>
</li>
<li class="chapter " data-level="5.10" data-path="ch5/ch5-10.html">
<a href="../ch5/ch5-10.html">
<i class="fa fa-check"></i>
<b>5.10.</b>
2015-12-28 08:08:26 +00:00
Recover捕獲異常
2015-12-09 07:57:17 +00:00
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="6" data-path="ch6/ch6.html">
<a href="../ch6/ch6.html">
<i class="fa fa-check"></i>
<b>6.</b>
方法
</a>
<ul class="articles">
<li class="chapter " data-level="6.1" data-path="ch6/ch6-01.html">
<a href="../ch6/ch6-01.html">
<i class="fa fa-check"></i>
<b>6.1.</b>
方法聲明
</a>
</li>
<li class="chapter " data-level="6.2" data-path="ch6/ch6-02.html">
<a href="../ch6/ch6-02.html">
<i class="fa fa-check"></i>
<b>6.2.</b>
2015-12-21 04:55:18 +00:00
基於指針對象的方法
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="6.3" data-path="ch6/ch6-03.html">
<a href="../ch6/ch6-03.html">
<i class="fa fa-check"></i>
<b>6.3.</b>
通過嵌入結構體來擴展類型
</a>
</li>
<li class="chapter " data-level="6.4" data-path="ch6/ch6-04.html">
<a href="../ch6/ch6-04.html">
<i class="fa fa-check"></i>
<b>6.4.</b>
2015-12-21 04:55:18 +00:00
方法值和方法表達式
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="6.5" data-path="ch6/ch6-05.html">
<a href="../ch6/ch6-05.html">
<i class="fa fa-check"></i>
<b>6.5.</b>
示例: Bit數組
</a>
</li>
<li class="chapter " data-level="6.6" data-path="ch6/ch6-06.html">
<a href="../ch6/ch6-06.html">
<i class="fa fa-check"></i>
<b>6.6.</b>
封裝
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="7" data-path="ch7/ch7.html">
<a href="../ch7/ch7.html">
<i class="fa fa-check"></i>
<b>7.</b>
接口
</a>
<ul class="articles">
<li class="chapter " data-level="7.1" data-path="ch7/ch7-01.html">
<a href="../ch7/ch7-01.html">
<i class="fa fa-check"></i>
<b>7.1.</b>
2015-12-21 04:55:18 +00:00
接口是合約
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="7.2" data-path="ch7/ch7-02.html">
<a href="../ch7/ch7-02.html">
<i class="fa fa-check"></i>
<b>7.2.</b>
接口類型
</a>
</li>
<li class="chapter " data-level="7.3" data-path="ch7/ch7-03.html">
<a href="../ch7/ch7-03.html">
<i class="fa fa-check"></i>
<b>7.3.</b>
實現接口的條件
</a>
</li>
<li class="chapter " data-level="7.4" data-path="ch7/ch7-04.html">
<a href="../ch7/ch7-04.html">
<i class="fa fa-check"></i>
<b>7.4.</b>
flag.Value接口
</a>
</li>
<li class="chapter " data-level="7.5" data-path="ch7/ch7-05.html">
<a href="../ch7/ch7-05.html">
<i class="fa fa-check"></i>
<b>7.5.</b>
接口值
</a>
</li>
<li class="chapter " data-level="7.6" data-path="ch7/ch7-06.html">
<a href="../ch7/ch7-06.html">
<i class="fa fa-check"></i>
<b>7.6.</b>
sort.Interface接口
</a>
</li>
<li class="chapter " data-level="7.7" data-path="ch7/ch7-07.html">
<a href="../ch7/ch7-07.html">
<i class="fa fa-check"></i>
<b>7.7.</b>
http.Handler接口
</a>
</li>
<li class="chapter " data-level="7.8" data-path="ch7/ch7-08.html">
<a href="../ch7/ch7-08.html">
<i class="fa fa-check"></i>
<b>7.8.</b>
error接口
</a>
</li>
<li class="chapter " data-level="7.9" data-path="ch7/ch7-09.html">
<a href="../ch7/ch7-09.html">
<i class="fa fa-check"></i>
<b>7.9.</b>
2015-12-21 04:55:18 +00:00
示例: 表達式求值
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="7.10" data-path="ch7/ch7-10.html">
<a href="../ch7/ch7-10.html">
<i class="fa fa-check"></i>
<b>7.10.</b>
類型斷言
</a>
</li>
<li class="chapter " data-level="7.11" data-path="ch7/ch7-11.html">
<a href="../ch7/ch7-11.html">
<i class="fa fa-check"></i>
<b>7.11.</b>
2015-12-21 04:55:18 +00:00
基於類型斷言識别錯誤類型
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="7.12" data-path="ch7/ch7-12.html">
<a href="../ch7/ch7-12.html">
<i class="fa fa-check"></i>
<b>7.12.</b>
通過類型斷言査詢接口
</a>
</li>
<li class="chapter " data-level="7.13" data-path="ch7/ch7-13.html">
<a href="../ch7/ch7-13.html">
<i class="fa fa-check"></i>
<b>7.13.</b>
類型分支
</a>
</li>
<li class="chapter " data-level="7.14" data-path="ch7/ch7-14.html">
<a href="../ch7/ch7-14.html">
<i class="fa fa-check"></i>
<b>7.14.</b>
示例: 基於標記的XML解碼
</a>
</li>
<li class="chapter " data-level="7.15" data-path="ch7/ch7-15.html">
<a href="../ch7/ch7-15.html">
<i class="fa fa-check"></i>
<b>7.15.</b>
補充幾點
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="8" data-path="ch8/ch8.html">
<a href="../ch8/ch8.html">
<i class="fa fa-check"></i>
<b>8.</b>
Goroutines和Channels
</a>
<ul class="articles">
<li class="chapter " data-level="8.1" data-path="ch8/ch8-01.html">
<a href="../ch8/ch8-01.html">
<i class="fa fa-check"></i>
<b>8.1.</b>
Goroutines
</a>
</li>
<li class="chapter " data-level="8.2" data-path="ch8/ch8-02.html">
<a href="../ch8/ch8-02.html">
<i class="fa fa-check"></i>
<b>8.2.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的Clock服務
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.3" data-path="ch8/ch8-03.html">
<a href="../ch8/ch8-03.html">
<i class="fa fa-check"></i>
<b>8.3.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的Echo服務
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.4" data-path="ch8/ch8-04.html">
<a href="../ch8/ch8-04.html">
<i class="fa fa-check"></i>
<b>8.4.</b>
Channels
</a>
</li>
<li class="chapter " data-level="8.5" data-path="ch8/ch8-05.html">
<a href="../ch8/ch8-05.html">
<i class="fa fa-check"></i>
<b>8.5.</b>
併行的循環
</a>
</li>
<li class="chapter " data-level="8.6" data-path="ch8/ch8-06.html">
<a href="../ch8/ch8-06.html">
<i class="fa fa-check"></i>
<b>8.6.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的Web爬蟲
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.7" data-path="ch8/ch8-07.html">
<a href="../ch8/ch8-07.html">
<i class="fa fa-check"></i>
<b>8.7.</b>
2015-12-21 04:55:18 +00:00
基於select的多路複用
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.8" data-path="ch8/ch8-08.html">
<a href="../ch8/ch8-08.html">
<i class="fa fa-check"></i>
<b>8.8.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的字典遍歷
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.9" data-path="ch8/ch8-09.html">
<a href="../ch8/ch8-09.html">
<i class="fa fa-check"></i>
<b>8.9.</b>
2015-12-28 08:08:26 +00:00
併發的退出
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.10" data-path="ch8/ch8-10.html">
<a href="../ch8/ch8-10.html">
<i class="fa fa-check"></i>
<b>8.10.</b>
示例: 聊天服務
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="9" data-path="ch9/ch9.html">
<a href="../ch9/ch9.html">
<i class="fa fa-check"></i>
<b>9.</b>
2015-12-21 04:55:18 +00:00
基於共享變量的併發
2015-12-09 07:57:17 +00:00
</a>
<ul class="articles">
<li class="chapter " data-level="9.1" data-path="ch9/ch9-01.html">
<a href="../ch9/ch9-01.html">
<i class="fa fa-check"></i>
<b>9.1.</b>
競爭條件
</a>
</li>
<li class="chapter " data-level="9.2" data-path="ch9/ch9-02.html">
<a href="../ch9/ch9-02.html">
<i class="fa fa-check"></i>
<b>9.2.</b>
sync.Mutex互斥鎖
</a>
</li>
<li class="chapter " data-level="9.3" data-path="ch9/ch9-03.html">
<a href="../ch9/ch9-03.html">
<i class="fa fa-check"></i>
<b>9.3.</b>
sync.RWMutex讀寫鎖
</a>
</li>
<li class="chapter " data-level="9.4" data-path="ch9/ch9-04.html">
<a href="../ch9/ch9-04.html">
<i class="fa fa-check"></i>
<b>9.4.</b>
2015-12-21 04:55:18 +00:00
內存同步
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="9.5" data-path="ch9/ch9-05.html">
<a href="../ch9/ch9-05.html">
<i class="fa fa-check"></i>
<b>9.5.</b>
sync.Once初始化
</a>
</li>
<li class="chapter " data-level="9.6" data-path="ch9/ch9-06.html">
<a href="../ch9/ch9-06.html">
<i class="fa fa-check"></i>
<b>9.6.</b>
競爭條件檢測
</a>
</li>
<li class="chapter " data-level="9.7" data-path="ch9/ch9-07.html">
<a href="../ch9/ch9-07.html">
<i class="fa fa-check"></i>
<b>9.7.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的非阻塞緩存
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="9.8" data-path="ch9/ch9-08.html">
<a href="../ch9/ch9-08.html">
<i class="fa fa-check"></i>
<b>9.8.</b>
2015-12-21 04:55:18 +00:00
Goroutines和線程
2015-12-09 07:57:17 +00:00
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="10" data-path="ch10/ch10.html">
<a href="../ch10/ch10.html">
<i class="fa fa-check"></i>
<b>10.</b>
包和工具
</a>
<ul class="articles">
<li class="chapter " data-level="10.1" data-path="ch10/ch10-01.html">
<a href="../ch10/ch10-01.html">
<i class="fa fa-check"></i>
<b>10.1.</b>
簡介
</a>
</li>
<li class="chapter " data-level="10.2" data-path="ch10/ch10-02.html">
<a href="../ch10/ch10-02.html">
<i class="fa fa-check"></i>
<b>10.2.</b>
導入路徑
</a>
</li>
<li class="chapter " data-level="10.3" data-path="ch10/ch10-03.html">
<a href="../ch10/ch10-03.html">
<i class="fa fa-check"></i>
<b>10.3.</b>
包聲明
</a>
</li>
<li class="chapter " data-level="10.4" data-path="ch10/ch10-04.html">
<a href="../ch10/ch10-04.html">
<i class="fa fa-check"></i>
<b>10.4.</b>
導入聲明
</a>
</li>
<li class="chapter " data-level="10.5" data-path="ch10/ch10-05.html">
<a href="../ch10/ch10-05.html">
<i class="fa fa-check"></i>
<b>10.5.</b>
匿名導入
</a>
</li>
<li class="chapter " data-level="10.6" data-path="ch10/ch10-06.html">
<a href="../ch10/ch10-06.html">
<i class="fa fa-check"></i>
<b>10.6.</b>
包和命名
</a>
</li>
<li class="chapter " data-level="10.7" data-path="ch10/ch10-07.html">
<a href="../ch10/ch10-07.html">
<i class="fa fa-check"></i>
<b>10.7.</b>
工具
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="11" data-path="ch11/ch11.html">
<a href="../ch11/ch11.html">
<i class="fa fa-check"></i>
<b>11.</b>
測試
</a>
<ul class="articles">
<li class="chapter " data-level="11.1" data-path="ch11/ch11-01.html">
<a href="../ch11/ch11-01.html">
<i class="fa fa-check"></i>
<b>11.1.</b>
go test
</a>
</li>
<li class="chapter " data-level="11.2" data-path="ch11/ch11-02.html">
<a href="../ch11/ch11-02.html">
<i class="fa fa-check"></i>
<b>11.2.</b>
測試函數
</a>
</li>
<li class="chapter " data-level="11.3" data-path="ch11/ch11-03.html">
<a href="../ch11/ch11-03.html">
<i class="fa fa-check"></i>
<b>11.3.</b>
測試覆蓋率
</a>
</li>
<li class="chapter " data-level="11.4" data-path="ch11/ch11-04.html">
<a href="../ch11/ch11-04.html">
<i class="fa fa-check"></i>
<b>11.4.</b>
基準測試
</a>
</li>
<li class="chapter " data-level="11.5" data-path="ch11/ch11-05.html">
<a href="../ch11/ch11-05.html">
<i class="fa fa-check"></i>
<b>11.5.</b>
剖析
</a>
</li>
<li class="chapter " data-level="11.6" data-path="ch11/ch11-06.html">
<a href="../ch11/ch11-06.html">
<i class="fa fa-check"></i>
<b>11.6.</b>
示例函數
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="12" data-path="ch12/ch12.html">
<a href="../ch12/ch12.html">
<i class="fa fa-check"></i>
<b>12.</b>
反射
</a>
<ul class="articles">
<li class="chapter " data-level="12.1" data-path="ch12/ch12-01.html">
<a href="../ch12/ch12-01.html">
<i class="fa fa-check"></i>
<b>12.1.</b>
2015-12-21 04:55:18 +00:00
爲何需要反射?
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.2" data-path="ch12/ch12-02.html">
<a href="../ch12/ch12-02.html">
<i class="fa fa-check"></i>
<b>12.2.</b>
reflect.Type和reflect.Value
</a>
</li>
<li class="chapter " data-level="12.3" data-path="ch12/ch12-03.html">
<a href="../ch12/ch12-03.html">
<i class="fa fa-check"></i>
<b>12.3.</b>
Display遞歸打印
</a>
</li>
<li class="chapter " data-level="12.4" data-path="ch12/ch12-04.html">
<a href="../ch12/ch12-04.html">
<i class="fa fa-check"></i>
<b>12.4.</b>
2015-12-21 04:55:18 +00:00
示例: 編碼S表達式
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.5" data-path="ch12/ch12-05.html">
<a href="../ch12/ch12-05.html">
<i class="fa fa-check"></i>
<b>12.5.</b>
通過reflect.Value脩改值
</a>
</li>
<li class="chapter " data-level="12.6" data-path="ch12/ch12-06.html">
<a href="../ch12/ch12-06.html">
<i class="fa fa-check"></i>
<b>12.6.</b>
2015-12-21 04:55:18 +00:00
示例: 解碼S表達式
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.7" data-path="ch12/ch12-07.html">
<a href="../ch12/ch12-07.html">
<i class="fa fa-check"></i>
<b>12.7.</b>
2015-12-28 08:08:26 +00:00
獲取結構體字段標識
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.8" data-path="ch12/ch12-08.html">
<a href="../ch12/ch12-08.html">
<i class="fa fa-check"></i>
<b>12.8.</b>
顯示一個類型的方法集
</a>
</li>
<li class="chapter " data-level="12.9" data-path="ch12/ch12-09.html">
<a href="../ch12/ch12-09.html">
<i class="fa fa-check"></i>
<b>12.9.</b>
幾點忠告
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="13" data-path="ch13/ch13.html">
<a href="../ch13/ch13.html">
<i class="fa fa-check"></i>
<b>13.</b>
底層編程
</a>
<ul class="articles">
<li class="chapter " data-level="13.1" data-path="ch13/ch13-01.html">
<a href="../ch13/ch13-01.html">
<i class="fa fa-check"></i>
<b>13.1.</b>
unsafe.Sizeof, Alignof 和 Offsetof
</a>
</li>
<li class="chapter " data-level="13.2" data-path="ch13/ch13-02.html">
<a href="../ch13/ch13-02.html">
<i class="fa fa-check"></i>
<b>13.2.</b>
unsafe.Pointer
</a>
</li>
<li class="chapter " data-level="13.3" data-path="ch13/ch13-03.html">
<a href="../ch13/ch13-03.html">
<i class="fa fa-check"></i>
<b>13.3.</b>
示例: 深度相等判斷
</a>
</li>
<li class="chapter " data-level="13.4" data-path="ch13/ch13-04.html">
<a href="../ch13/ch13-04.html">
<i class="fa fa-check"></i>
<b>13.4.</b>
通過cgo調用C代碼
</a>
</li>
<li class="chapter " data-level="13.5" data-path="ch13/ch13-05.html">
<a href="../ch13/ch13-05.html">
<i class="fa fa-check"></i>
<b>13.5.</b>
幾點忠告
</a>
</li>
</ul>
</li>
2015-12-24 06:47:06 +00:00
<li class="chapter " data-level="14" data-path="CONTRIBUTORS.html">
2015-12-09 07:57:17 +00:00
2015-12-24 06:47:06 +00:00
<a href="../CONTRIBUTORS.html">
2015-12-09 07:57:17 +00:00
<i class="fa fa-check"></i>
2015-12-21 04:55:18 +00:00
<b>14.</b>
2015-12-09 07:57:17 +00:00
2015-12-24 06:47:06 +00:00
附録
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
本書使用 GitBook 釋出
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Actions Left -->
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
2015-12-31 08:20:27 +00:00
<a href="../" >Go语言圣经</a>
2015-12-09 07:57:17 +00:00
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<h2 id="45-json">4.5. JSON</h2>
2015-12-31 08:20:27 +00:00
<p>JavaScript&#x5C0D;&#x8C61;&#x8868;&#x793A;&#x6CD5;&#xFF08;JSON&#xFF09;&#x662F;&#x4E00;&#x7A2E;&#x7528;&#x65BC;&#x767C;&#x9001;&#x548C;&#x63A5;&#x6536;&#x7D50;&#x69CB;&#x5316;&#x4FE1;&#x606F;&#x7684;&#x6A19;&#x6E96;&#x5354;&#x8B70;&#x3002;JSON&#x4F75;&#x4E0D;&#x662F;&#x552F;&#x4E00;&#x6A19;&#x6E96;&#x5354;&#x8B70;&#x3002; XML&#xFF08;&#xA7;7.14&#xFF09;&#x3001;ASN.1&#x548C;Google&#x7684;Protocol Buffers&#x90FD;&#x662F;&#x985E;&#x4F3C;&#x7684;&#x5354;&#x8B70;&#xFF0C;&#x4F75;&#x4E14;&#x6709;&#x5404;&#x81EA;&#x7684;&#x7279;&#x8272;&#xFF0C;&#x4F46;&#x662F;&#x7531;&#x65BC;&#x7C21;&#x6F54;&#x6027;&#x3001;&#x53EF;&#x8B80;&#x6027;&#x548C;&#x6D41;&#x884C;&#x7A0B;&#x5EA6;&#x7B49;&#x539F;&#x56E0;&#xFF0C;JSON&#x662F;&#x61C9;&#x7528;&#x6700;&#x5EE3;&#x6CDB;&#x7684;&#x4E00;&#x500B;&#x3002;</p>
<p>Go&#x8A9E;&#x8A00;&#x5C0D;&#x65BC;&#x9019;&#x4E9B;&#x6A19;&#x6E96;&#x683C;&#x5F0F;&#x7684;&#x7DE8;&#x78BC;&#x548C;&#x89E3;&#x78BC;&#x90FD;&#x6709;&#x826F;&#x597D;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x7531;&#x6A19;&#x6E96;&#x5EAB;&#x4E2D;&#x7684;encoding/json&#x3001;encoding/xml&#x3001;encoding/asn1&#x7B49;&#x5305;&#x63D0;&#x4F9B;&#xFF08;&#x8B6F;&#x8A3B;&#xFF1A;Protocol Buffers&#x7684;&#x652F;&#x6301;&#x7531; github.com/golang/protobuf &#x5305;&#x63D0;&#x4F9B;&#xFF09;&#xFF0C;&#x4F75;&#x4E14;&#x9019;&#x985E;&#x5305;&#x90FD;&#x6709;&#x7740;&#x76F8;&#x4F3C;&#x7684;API&#x63A5;&#x53E3;&#x3002;&#x672C;&#x7BC0;&#xFF0C;&#x6211;&#x5011;&#x5C07;&#x5C0D;&#x91CD;&#x8981;&#x7684;encoding/json&#x5305;&#x7684;&#x7528;&#x6CD5;&#x505A;&#x500B;&#x6982;&#x8FF0;&#x3002;</p>
<p>JSON&#x662F;&#x5C0D;JavaScript&#x4E2D;&#x5404;&#x7A2E;&#x503C;&#x2014;&#x2014;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x6578;&#x5B57;&#x3001;&#x5E03;&#x723E;&#x503C;&#x548C;&#x5C0D;&#x8C61;&#x2014;&#x2014;Unicode&#x672C;&#x6587;&#x7DE8;&#x78BC;&#x3002;&#x5B83;&#x53EF;&#x4EE5;&#x7528;&#x6709;&#x6548;&#x53EF;&#x8B80;&#x7684;&#x65B9;&#x5F0F;&#x8868;&#x793A;&#x7B2C;&#x4E09;&#x7AE0;&#x7684;&#x57FA;&#x790E;&#x6578;&#x64DA;&#x985E;&#x578B;&#x548C;&#x672C;&#x7AE0;&#x7684;&#x6578;&#x7D44;&#x3001;slice&#x3001;&#x7D50;&#x69CB;&#x9AD4;&#x548C;map&#x7B49;&#x805A;&#x5408;&#x6578;&#x64DA;&#x985E;&#x578B;&#x3002;</p>
<p>&#x57FA;&#x672C;&#x7684;JSON&#x985E;&#x578B;&#x6709;&#x6578;&#x5B57;&#xFF08;&#x5341;&#x9032;&#x88FD;&#x6216;&#x79D1;&#x5B78;&#x8A18;&#x6578;&#x6CD5;&#xFF09;&#x3001;&#x5E03;&#x723E;&#x503C;&#xFF08;true&#x6216;false&#xFF09;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5176;&#x4E2D;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x4EE5;&#x96D9;&#x5F15;&#x865F;&#x5305;&#x542B;&#x7684;Unicode&#x5B57;&#x7B26;&#x5E8F;&#x5217;&#xFF0C;&#x652F;&#x6301;&#x548C;Go&#x8A9E;&#x8A00;&#x985E;&#x4F3C;&#x7684;&#x53CD;&#x659C;&#x69D3;&#x8F49;&#x7FA9;&#x7279;&#x6027;&#xFF0C;&#x4E0D;&#x904E;JSON&#x4F7F;&#x7528;&#x7684;&#x662F;\Uhhhh&#x8F49;&#x7FA9;&#x6578;&#x5B57;&#x4F86;&#x8868;&#x793A;&#x4E00;&#x500B;UTF-16&#x7DE8;&#x78BC;&#xFF0C;&#x800C;&#x4E0D;&#x662F;Go&#x8A9E;&#x8A00;&#x7684;rune&#x985E;&#x578B;&#x3002;</p>
<p>&#x9019;&#x4E9B;&#x57FA;&#x790E;&#x985E;&#x578B;&#x53EF;&#x4EE5;&#x901A;&#x904E;JSON&#x7684;&#x6578;&#x7D44;&#x548C;&#x5C0D;&#x8C61;&#x985E;&#x578B;&#x9032;&#x884C;&#x905E;&#x6B78;&#x7D44;&#x5408;&#x3002;&#x4E00;&#x500B;JSON&#x6578;&#x7D44;&#x662F;&#x4E00;&#x500B;&#x6709;&#x5E8F;&#x7684;&#x503C;&#x5E8F;&#x5217;&#xFF0C;&#x5BEB;&#x5728;&#x4E00;&#x500B;&#x65B9;&#x62EC;&#x865F;&#x4E2D;&#x4F75;&#x4EE5;&#x9017;&#x865F;&#x5206;&#x9694;&#xFF1B;&#x4E00;&#x500B;JSON&#x6578;&#x7D44;&#x53EF;&#x4EE5;&#x7528;&#x65BC;&#x7DE8;&#x78BC;Go&#x8A9E;&#x8A00;&#x7684;&#x6578;&#x7D44;&#x548C;slice&#x3002;&#x4E00;&#x500B;JSON&#x5C0D;&#x8C61;&#x662F;&#x4E00;&#x500B;&#x5B57;&#x7B26;&#x4E32;&#x5230;&#x503C;&#x7684;&#x6620;&#x5C04;&#xFF0C;&#x5BEB;&#x6210;&#x4EE5;&#x7E6B;&#x5217;&#x7684;name:value&#x5C0D;&#x5F62;&#x5F0F;&#xFF0C;&#x7528;&#x82B1;&#x62EC;&#x865F;&#x5305;&#x542B;&#x4F75;&#x4EE5;&#x9017;&#x865F;&#x5206;&#x9694;&#xFF1B;JSON&#x7684;&#x5C0D;&#x8C61;&#x985E;&#x578B;&#x53EF;&#x4EE5;&#x7528;&#x65BC;&#x7DE8;&#x78BC;Go&#x8A9E;&#x8A00;&#x7684;map&#x985E;&#x578B;&#xFF08;key&#x985E;&#x578B;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#xFF09;&#x548C;&#x7D50;&#x69CB;&#x9AD4;&#x3002;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code>boolean true
number -273.15
string &quot;She said \&quot;Hello, BF\&quot;&quot;
array [&quot;gold&quot;, &quot;silver&quot;, &quot;bronze&quot;]
object {&quot;year&quot;: 1980,
&quot;event&quot;: &quot;archery&quot;,
&quot;medals&quot;: [&quot;gold&quot;, &quot;silver&quot;, &quot;bronze&quot;]}
</code></pre><p>&#x8003;&#x616E;&#x4E00;&#x500B;&#x61C9;&#x7528;&#x7A0B;&#x5E8F;&#xFF0C;&#x8A72;&#x7A0B;&#x5E8F;&#x8CA0;&#x8CAC;&#x6536;&#x96C6;&#x5404;&#x7A2E;&#x96FB;&#x5F71;&#x8A55;&#x8AD6;&#x4F75;&#x63D0;&#x4F9B;&#x53CD;&#x994B;&#x529F;&#x80FD;&#x3002;&#x5B83;&#x7684;Movie&#x6578;&#x64DA;&#x985E;&#x578B;&#x548C;&#x4E00;&#x500B;&#x5178;&#x578B;&#x7684;&#x8868;&#x793A;&#x96FB;&#x5F71;&#x7684;&#x503C;&#x5217;&#x8868;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;&#xFF08;&#x5176;&#x4E2D;&#x7D50;&#x69CB;&#x9AD4;&#x8072;&#x660E;&#x4E2D;&#xFF0C;Year&#x548C;Color&#x6210;&#x54E1;&#x5F8C;&#x9762;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x9762;&#x503C;&#x662F;&#x7D50;&#x69CB;&#x9AD4;&#x6210;&#x54E1;Tag&#xFF1B;&#x6211;&#x5011;&#x7A0D;&#x5F8C;&#x6703;&#x89E3;&#x91CB;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x3002;&#xFF09;</p>
<pre><code class="lang-Go">gopl.io/ch4/movie
<span class="hljs-keyword">type</span> Movie <span class="hljs-keyword">struct</span> {
Title <span class="hljs-typename">string</span>
Year <span class="hljs-typename">int</span> <span class="hljs-string">`json:&quot;released&quot;`</span>
Color <span class="hljs-typename">bool</span> <span class="hljs-string">`json:&quot;color,omitempty&quot;`</span>
Actors []<span class="hljs-typename">string</span>
}
<span class="hljs-keyword">var</span> movies = []Movie{
{Title: <span class="hljs-string">&quot;Casablanca&quot;</span>, Year: <span class="hljs-number">1942</span>, Color: <span class="hljs-constant">false</span>,
Actors: []<span class="hljs-typename">string</span>{<span class="hljs-string">&quot;Humphrey Bogart&quot;</span>, <span class="hljs-string">&quot;Ingrid Bergman&quot;</span>}},
{Title: <span class="hljs-string">&quot;Cool Hand Luke&quot;</span>, Year: <span class="hljs-number">1967</span>, Color: <span class="hljs-constant">true</span>,
Actors: []<span class="hljs-typename">string</span>{<span class="hljs-string">&quot;Paul Newman&quot;</span>}},
{Title: <span class="hljs-string">&quot;Bullitt&quot;</span>, Year: <span class="hljs-number">1968</span>, Color: <span class="hljs-constant">true</span>,
Actors: []<span class="hljs-typename">string</span>{<span class="hljs-string">&quot;Steve McQueen&quot;</span>, <span class="hljs-string">&quot;Jacqueline Bisset&quot;</span>}},
<span class="hljs-comment">// ...</span>
}
</code></pre>
<p>&#x9019;&#x6A23;&#x7684;&#x6578;&#x64DA;&#x7D50;&#x69CB;&#x7279;&#x522B;&#x9069;&#x5408;JSON&#x683C;&#x5F0F;&#xFF0C;&#x4F75;&#x4E14;&#x5728;&#x5169;&#x7A2E;&#x4E4B;&#x9593;&#x76F8;&#x4E92;&#x8F49;&#x63DB;&#x4E5F;&#x5F88;&#x5BB9;&#x6613;&#x3002;&#x5C07;&#x4E00;&#x500B;Go&#x8A9E;&#x8A00;&#x4E2D;&#x985E;&#x4F3C;movies&#x7684;&#x7D50;&#x69CB;&#x9AD4;slice&#x8F49;&#x7232;JSON&#x7684;&#x904E;&#x7A0B;&#x53EB;&#x7DE8;&#x7D44;&#xFF08;marshaling&#xFF09;&#x3002;&#x7DE8;&#x7D44;&#x901A;&#x904E;&#x8ABF;&#x7528;json.Marshal&#x51FD;&#x6578;&#x5B8C;&#x6210;&#xFF1A;</p>
<pre><code class="lang-Go">data, err := json.Marshal(movies)
<span class="hljs-keyword">if</span> err != <span class="hljs-constant">nil</span> {
log.Fatalf(<span class="hljs-string">&quot;JSON marshaling failed: %s&quot;</span>, err)
}
fmt.Printf(<span class="hljs-string">&quot;%s\n&quot;</span>, data)
</code></pre>
<p>Marshal&#x51FD;&#x6578;&#x751F;&#x6210;&#x4E00;&#x500B;&#x5B57;&#x7BC0;slice&#xFF0C;&#x5305;&#x542B;&#x5F88;&#x9577;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4F75;&#x4E14;&#x6C92;&#x6709;&#x7A7A;&#x767D;&#x7E2E;&#x9032;&#xFF1B;&#x6211;&#x5011;&#x5C07;&#x5B83;&#x647A;&#x884C;&#x4EE5;&#x4FBF;&#x65BC;&#x986F;&#x793A;&#xFF1A;</p>
<pre><code>[{&quot;Title&quot;:&quot;Casablanca&quot;,&quot;released&quot;:1942,&quot;Actors&quot;:[&quot;Humphrey Bogart&quot;,&quot;Ingr
id Bergman&quot;]},{&quot;Title&quot;:&quot;Cool Hand Luke&quot;,&quot;released&quot;:1967,&quot;color&quot;:true,&quot;Ac
tors&quot;:[&quot;Paul Newman&quot;]},{&quot;Title&quot;:&quot;Bullitt&quot;,&quot;released&quot;:1968,&quot;color&quot;:true,&quot;
Actors&quot;:[&quot;Steve McQueen&quot;,&quot;Jacqueline Bisset&quot;]}]
</code></pre><p>&#x9019;&#x7A2E;&#x7DCA;&#x6E4A;&#x7684;&#x8868;&#x793A;&#x5F62;&#x5F0F;&#x96D6;&#x7136;&#x5305;&#x542B;&#x4E86;&#x5168;&#x90E8;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x4F46;&#x662F;&#x5F88;&#x96E3;&#x95B2;&#x8B80;&#x3002;&#x7232;&#x4E86;&#x751F;&#x6210;&#x4FBF;&#x65BC;&#x95B2;&#x8B80;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x53E6;&#x4E00;&#x500B;json.MarshalIndent&#x51FD;&#x6578;&#x5C07;&#x7523;&#x751F;&#x6574;&#x9F4A;&#x7E2E;&#x9032;&#x7684;&#x8F38;&#x51FA;&#x3002;&#x6709;&#x5169;&#x500B;&#x984D;&#x5916;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x53C3;&#x6578;&#x7528;&#x65BC;&#x8868;&#x793A;&#x6BCF;&#x4E00;&#x884C;&#x8F38;&#x51FA;&#x7684;&#x524D;&#x7DB4;&#x548C;&#x6BCF;&#x4E00;&#x500B;&#x5C64;&#x7D1A;&#x7684;&#x7E2E;&#x9032;&#xFF1A;</p>
<pre><code class="lang-Go">data, err := json.MarshalIndent(movies, <span class="hljs-string">&quot;&quot;</span>, <span class="hljs-string">&quot; &quot;</span>)
<span class="hljs-keyword">if</span> err != <span class="hljs-constant">nil</span> {
log.Fatalf(<span class="hljs-string">&quot;JSON marshaling failed: %s&quot;</span>, err)
}
fmt.Printf(<span class="hljs-string">&quot;%s\n&quot;</span>, data)
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x78BC;&#x5C07;&#x7523;&#x751F;&#x9019;&#x6A23;&#x7684;&#x8F38;&#x51FA;&#xFF1A;</p>
<pre><code class="lang-Json">[
{
<span class="hljs-string">&quot;Title&quot;</span>: <span class="hljs-string">&quot;Casablanca&quot;</span>,
<span class="hljs-string">&quot;released&quot;</span>: <span class="hljs-number">1942</span>,
<span class="hljs-string">&quot;Actors&quot;</span>: [
<span class="hljs-string">&quot;Humphrey Bogart&quot;</span>,
<span class="hljs-string">&quot;Ingrid Bergman&quot;</span>
]
},
{
<span class="hljs-string">&quot;Title&quot;</span>: <span class="hljs-string">&quot;Cool Hand Luke&quot;</span>,
<span class="hljs-string">&quot;released&quot;</span>: <span class="hljs-number">1967</span>,
<span class="hljs-string">&quot;color&quot;</span>: <span class="hljs-literal">true</span>,
<span class="hljs-string">&quot;Actors&quot;</span>: [
<span class="hljs-string">&quot;Paul Newman&quot;</span>
]
},
{
<span class="hljs-string">&quot;Title&quot;</span>: <span class="hljs-string">&quot;Bullitt&quot;</span>,
<span class="hljs-string">&quot;released&quot;</span>: <span class="hljs-number">1968</span>,
<span class="hljs-string">&quot;color&quot;</span>: <span class="hljs-literal">true</span>,
<span class="hljs-string">&quot;Actors&quot;</span>: [
<span class="hljs-string">&quot;Steve McQueen&quot;</span>,
<span class="hljs-string">&quot;Jacqueline Bisset&quot;</span>
]
}
]
</code></pre>
<p>&#x5728;&#x7DE8;&#x78BC;&#x6642;&#xFF0C;&#x9ED8;&#x8A8D;&#x4F7F;&#x7528;Go&#x8A9E;&#x8A00;&#x7D50;&#x69CB;&#x9AD4;&#x7684;&#x6210;&#x54E1;&#x540D;&#x5B57;&#x4F5C;&#x7232;JSON&#x7684;&#x5C0D;&#x8C61;&#xFF08;&#x901A;&#x904E;reflect&#x53CD;&#x5C04;&#x6280;&#x8853;&#xFF0C;&#x6211;&#x5011;&#x5C07;&#x5728;12.6&#x7BC0;&#x8A0E;&#x8AD6;&#xFF09;&#x3002;&#x96BB;&#x6709;&#x5C0E;&#x51FA;&#x7684;&#x7D50;&#x69CB;&#x9AD4;&#x6210;&#x54E1;&#x624D;&#x6703;&#x88AB;&#x7DE8;&#x78BC;&#xFF0C;&#x9019;&#x4E5F;&#x5C31;&#x662F;&#x6211;&#x5011;&#x7232;&#x4EC0;&#x9EBD;&#x9078;&#x64C7;&#x7528;&#x5927;&#x5BEB;&#x5B57;&#x6BCD;&#x958B;&#x982D;&#x7684;&#x6210;&#x54E1;&#x540D;&#x7A31;&#x3002;</p>
<p>&#x7D30;&#x5FC3;&#x7684;&#x8B80;&#x8005;&#x53EF;&#x80FD;&#x5DF2;&#x7D93;&#x8A3B;&#x610F;&#x5230;&#xFF0C;&#x5176;&#x4E2D;Year&#x540D;&#x5B57;&#x7684;&#x6210;&#x54E1;&#x5728;&#x7DE8;&#x78BC;&#x5F8C;&#x8B8A;&#x6210;&#x4E86;released&#xFF0C;&#x9084;&#x6709;Color&#x9577;&#x9060;&#x7DE8;&#x78BC;&#x5F8C;&#x8B8A;&#x6210;&#x4E86;&#x5C0F;&#x5BEB;&#x5B57;&#x6BCD;&#x958B;&#x982D;&#x7684;color&#x3002;&#x9019;&#x662F;&#x56E0;&#x7232;&#x69CB;&#x9AD4;&#x6210;&#x54E1;Tag&#x6240;&#x5C0E;&#x81F4;&#x7684;&#x3002;&#x4E00;&#x500B;&#x69CB;&#x9AD4;&#x6210;&#x54E1;Tag&#x662F;&#x548C;&#x5728;&#x7DE8;&#x8B6F;&#x968E;&#x6BB5;&#x95DC;&#x806F;&#x5230;&#x8A72;&#x6210;&#x54E1;&#x7684;&#x5143;&#x4FE1;&#x606F;&#x5B57;&#x7B26;&#x4E32;&#xFF1A;</p>
<pre><code>Year int `json:&quot;released&quot;`
Color bool `json:&quot;color,omitempty&quot;`
</code></pre><p>&#x7D50;&#x69CB;&#x9AD4;&#x7684;&#x6210;&#x54E1;Tag&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x610F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x9762;&#x503C;&#xFF0C;&#x4F46;&#x662F;&#x901A;&#x5E38;&#x662F;&#x4E00;&#x7E6B;&#x5217;&#x7528;&#x7A7A;&#x683C;&#x5206;&#x9694;&#x7684;key:&quot;value&quot;&#x9375;&#x503C;&#x5C0D;&#x5E8F;&#x5217;&#xFF1B;&#x56E0;&#x7232;&#x503C;&#x4E2D;&#x542B;&#x7FA9;&#x96D9;&#x5F15;&#x865F;&#x5B57;&#x7B26;&#xFF0C;&#x56E0;&#x6B64;&#x6210;&#x54E1;Tag&#x4E00;&#x822C;&#x7528;&#x539F;&#x751F;&#x5B57;&#x7B26;&#x4E32;&#x9762;&#x503C;&#x7684;&#x5F62;&#x5F0F;&#x66F8;&#x5BEB;&#x3002;json&#x958B;&#x982D;&#x9375;&#x5C0D;&#x61C9;&#x7684;&#x503C;&#x7528;&#x65BC;&#x63A7;&#x88FD;encoding/json&#x5305;&#x7684;&#x7DE8;&#x78BC;&#x548C;&#x89E3;&#x78BC;&#x7684;&#x884C;&#x7232;&#xFF0C;&#x4F75;&#x4E14;encoding/...&#x4E0B;&#x9762;&#x5176;&#x5B83;&#x7684;&#x5305;&#x4E5F;&#x9075;&#x5FAA;&#x9019;&#x500B;&#x7D04;&#x5B9A;&#x3002;&#x6210;&#x54E1;Tag&#x4E2D;json&#x5C0D;&#x61C9;&#x503C;&#x7684;&#x7B2C;&#x4E00;&#x90E8;&#x5206;&#x7528;&#x65BC;&#x6307;&#x5B9A;JSON&#x5C0D;&#x8C61;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x6BD4;&#x5982;&#x5C07;Go&#x8A9E;&#x8A00;&#x4E2D;&#x7684;TotalCount&#x6210;&#x54E1;&#x5C0D;&#x61C9;&#x5230;JSON&#x4E2D;&#x7684;total_count&#x5C0D;&#x8C61;&#x3002;Color&#x6210;&#x54E1;&#x7684;Tag&#x9084;&#x5E36;&#x4E86;&#x4E00;&#x500B;&#x984D;&#x5916;&#x7684;omitempty&#x9078;&#x9805;&#xFF0C;&#x8868;&#x793A;&#x7576;Go&#x8A9E;&#x8A00;&#x7D50;&#x69CB;&#x9AD4;&#x6210;&#x54E1;&#x7232;&#x7A7A;&#x6216;&#x96F6;&#x503C;&#x6642;&#x4E0D;&#x751F;&#x6210;JSON&#x5C0D;&#x8C61;&#xFF08;&#x9019;&#x91CC;false&#x7232;&#x96F6;&#x503C;&#xFF09;&#x3002;&#x679C;&#x7136;&#xFF0C;Casablanca&#x662F;&#x4E00;&#x500B;&#x9ED1;&#x767D;&#x96FB;&#x5F71;&#xFF0C;&#x4F75;&#x6C92;&#x6709;&#x8F38;&#x51FA;Color&#x6210;&#x54E1;&#x3002;</p>
<p>&#x7DE8;&#x78BC;&#x7684;&#x9006;&#x64CD;&#x4F5C;&#x662F;&#x89E3;&#x78BC;&#xFF0C;&#x5C0D;&#x61C9;&#x5C07;JSON&#x6578;&#x64DA;&#x89E3;&#x78BC;&#x7232;GO&#x8A9E;&#x8A00;&#x7684;&#x6578;&#x64DA;&#x7D50;&#x69CB;&#xFF0C;Go&#x8A9E;&#x8A00;&#x4E2D;&#x4E00;&#x822C;&#x53EB;unmarshaling&#xFF0C;&#x901A;&#x904E;json.Unmarshal&#x51FD;&#x6578;&#x5B8C;&#x6210;&#x3002;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x78BC;&#x5C07;JSON&#x683C;&#x5F0F;&#x7684;&#x96FB;&#x5F71;&#x6578;&#x64DA;&#x89E3;&#x78BC;&#x7232;&#x4E00;&#x500B;&#x7D50;&#x69CB;&#x9AD4;slice&#xFF0C;&#x7D50;&#x69CB;&#x9AD4;&#x4E2D;&#x96BB;&#x6709;Title&#x6210;&#x54E1;&#x3002;&#x901A;&#x904E;&#x5B9A;&#x7FA9;&#x5408;&#x9069;&#x7684;Go&#x8A9E;&#x8A00;&#x6578;&#x64DA;&#x7D50;&#x69CB;&#xFF0C;&#x6211;&#x5011;&#x53EF;&#x4EE5;&#x9078;&#x64C7;&#x6027;&#x5730;&#x89E3;&#x78BC;JSON&#x4E2D;&#x611F;&#x8208;&#x8DA3;&#x7684;&#x6210;&#x54E1;&#x3002;&#x7576;Unmarshal&#x8FD4;&#x8FF4;&#xFF0C;slice&#x5C07;&#x88AB;&#x96BB;&#x542B;&#x6709;Title&#x4FE1;&#x606F;&#x503C;&#x586B;&#x5145;&#xFF0C;&#x5176;&#x5B83;JSON&#x6210;&#x54E1;&#x5C07;&#x88AB;&#x5FFD;&#x7565;&#x3002;</p>
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> titles []<span class="hljs-keyword">struct</span>{ Title <span class="hljs-typename">string</span> }
<span class="hljs-keyword">if</span> err := json.Unmarshal(data, &amp;titles); err != <span class="hljs-constant">nil</span> {
log.Fatalf(<span class="hljs-string">&quot;JSON unmarshaling failed: %s&quot;</span>, err)
}
fmt.Println(titles) <span class="hljs-comment">// &quot;[{Casablanca} {Cool Hand Luke} {Bullitt}]&quot;</span>
</code></pre>
<p>&#x8A31;&#x591A;web&#x670D;&#x52D9;&#x90FD;&#x63D0;&#x4F9B;JSON&#x63A5;&#x53E3;&#xFF0C;&#x901A;&#x904E;HTTP&#x63A5;&#x53E3;&#x767C;&#x9001;JSON&#x683C;&#x5F0F;&#x8ACB;&#x6C42;&#x4F75;&#x8FD4;&#x8FF4;JSON&#x683C;&#x5F0F;&#x7684;&#x4FE1;&#x606F;&#x3002;&#x7232;&#x4E86;&#x8AAC;&#x660E;&#x9019;&#x4E00;&#x9EDE;&#xFF0C;&#x6211;&#x5011;&#x901A;&#x904E;Github&#x7684;issue&#x67FB;&#x8A62;&#x670D;&#x52D9;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x6211;&#x5011;&#x8981;&#x5B9A;&#x7FA9;&#x5408;&#x9069;&#x7684;&#x985E;&#x578B;&#x548C;&#x5E38;&#x91CF;&#xFF1A;</p>
<pre><code class="lang-Go">gopl.io/ch4/github
<span class="hljs-comment">// Package github provides a Go API for the GitHub issue tracker.</span>
<span class="hljs-comment">// See https://developer.github.com/v3/search/#search-issues.</span>
<span class="hljs-keyword">package</span> github
<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;time&quot;</span>
<span class="hljs-keyword">const</span> IssuesURL = <span class="hljs-string">&quot;https://api.github.com/search/issues&quot;</span>
<span class="hljs-keyword">type</span> IssuesSearchResult <span class="hljs-keyword">struct</span> {
TotalCount <span class="hljs-typename">int</span> <span class="hljs-string">`json:&quot;total_count&quot;`</span>
Items []*Issue
}
<span class="hljs-keyword">type</span> Issue <span class="hljs-keyword">struct</span> {
Number <span class="hljs-typename">int</span>
HTMLURL <span class="hljs-typename">string</span> <span class="hljs-string">`json:&quot;html_url&quot;`</span>
Title <span class="hljs-typename">string</span>
State <span class="hljs-typename">string</span>
User *User
CreatedAt time.Time <span class="hljs-string">`json:&quot;created_at&quot;`</span>
Body <span class="hljs-typename">string</span> <span class="hljs-comment">// in Markdown format</span>
}
<span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> {
Login <span class="hljs-typename">string</span>
HTMLURL <span class="hljs-typename">string</span> <span class="hljs-string">`json:&quot;html_url&quot;`</span>
}
</code></pre>
<p>&#x548C;&#x524D;&#x9762;&#x4E00;&#x6A23;&#xFF0C;&#x537D;&#x4F7F;&#x5C0D;&#x61C9;&#x7684;JSON&#x5C0D;&#x8C61;&#x540D;&#x662F;&#x5C0F;&#x5BEB;&#x5B57;&#x6BCD;&#xFF0C;&#x6BCF;&#x500B;&#x7D50;&#x69CB;&#x9AD4;&#x7684;&#x6210;&#x54E1;&#x540D;&#x4E5F;&#x662F;&#x8072;&#x660E;&#x7232;&#x5927;&#x5C0F;&#x5B57;&#x6BCD;&#x958B;&#x982D;&#x7684;&#x3002;&#x56E0;&#x7232;&#x6709;&#x4E9B;JSON&#x6210;&#x54E1;&#x540D;&#x5B57;&#x548C;Go&#x7D50;&#x69CB;&#x9AD4;&#x6210;&#x54E1;&#x540D;&#x5B57;&#x4F75;&#x4E0D;&#x76F8;&#x540C;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;Go&#x8A9E;&#x8A00;&#x7D50;&#x69CB;&#x9AD4;&#x6210;&#x54E1;Tag&#x4F86;&#x6307;&#x5B9A;&#x5C0D;&#x61C9;&#x7684;JSON&#x540D;&#x5B57;&#x3002;&#x540C;&#x6A23;&#xFF0C;&#x5728;&#x89E3;&#x78BC;&#x7684;&#x6642;&#x5019;&#x4E5F;&#x9700;&#x8981;&#x505A;&#x540C;&#x6A23;&#x7684;&#x8655;&#x7406;&#xFF0C;GitHub&#x670D;&#x52D9;&#x8FD4;&#x8FF4;&#x7684;&#x4FE1;&#x606F;&#x6BD4;&#x6211;&#x5011;&#x5B9A;&#x7FA9;&#x7684;&#x8981;&#x591A;&#x5F88;&#x591A;&#x3002;</p>
<p>SearchIssues&#x51FD;&#x6578;&#x767C;&#x51FA;&#x4E00;&#x500B;HTTP&#x8ACB;&#x6C42;&#xFF0C;&#x7136;&#x5F8C;&#x89E3;&#x78BC;&#x8FD4;&#x8FF4;&#x7684;JSON&#x683C;&#x5F0F;&#x7684;&#x7D50;&#x679C;&#x3002;&#x56E0;&#x7232;&#x7528;&#x6236;&#x63D0;&#x4F9B;&#x7684;&#x67FB;&#x8A62;&#x689D;&#x4EF6;&#x53EF;&#x80FD;&#x5305;&#x542B;&#x985E;&#x4F3C;<code>?</code>&#x548C;<code>&amp;</code>&#x4E4B;&#x985E;&#x7684;&#x7279;&#x6B8A;&#x5B57;&#x7B26;&#xFF0C;&#x7232;&#x4E86;&#x907F;&#x514D;&#x5C0D;URL&#x9020;&#x6210;&#x885D;&#x7A81;&#xFF0C;&#x6211;&#x5011;&#x7528;url.QueryEscape&#x4F86;&#x5C0D;&#x67FB;&#x8A62;&#x4E2D;&#x7684;&#x7279;&#x6B8A;&#x5B57;&#x7B26;&#x9032;&#x884C;&#x8F49;&#x7FA9;&#x64CD;&#x4F5C;&#x3002;</p>
<pre><code class="lang-Go">gopl.io/ch4/github
<span class="hljs-keyword">package</span> github
<span class="hljs-keyword">import</span> (
<span class="hljs-string">&quot;encoding/json&quot;</span>
<span class="hljs-string">&quot;fmt&quot;</span>
<span class="hljs-string">&quot;net/http&quot;</span>
<span class="hljs-string">&quot;net/url&quot;</span>
<span class="hljs-string">&quot;strings&quot;</span>
)
<span class="hljs-comment">// SearchIssues queries the GitHub issue tracker.</span>
<span class="hljs-keyword">func</span> SearchIssues(terms []<span class="hljs-typename">string</span>) (*IssuesSearchResult, error) {
q := url.QueryEscape(strings.Join(terms, <span class="hljs-string">&quot; &quot;</span>))
resp, err := http.Get(IssuesURL + <span class="hljs-string">&quot;?q=&quot;</span> + q)
<span class="hljs-keyword">if</span> err != <span class="hljs-constant">nil</span> {
<span class="hljs-keyword">return</span> <span class="hljs-constant">nil</span>, err
}
<span class="hljs-comment">// We must close resp.Body on all execution paths.</span>
<span class="hljs-comment">// (Chapter 5 presents &apos;defer&apos;, which makes this simpler.)</span>
<span class="hljs-keyword">if</span> resp.StatusCode != http.StatusOK {
resp.Body.Close()
<span class="hljs-keyword">return</span> <span class="hljs-constant">nil</span>, fmt.Errorf(<span class="hljs-string">&quot;search query failed: %s&quot;</span>, resp.Status)
}
<span class="hljs-keyword">var</span> result IssuesSearchResult
<span class="hljs-keyword">if</span> err := json.NewDecoder(resp.Body).Decode(&amp;result); err != <span class="hljs-constant">nil</span> {
resp.Body.Close()
<span class="hljs-keyword">return</span> <span class="hljs-constant">nil</span>, err
}
resp.Body.Close()
<span class="hljs-keyword">return</span> &amp;result, <span class="hljs-constant">nil</span>
}
</code></pre>
<p>&#x5728;&#x65E9;&#x4E9B;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x5011;&#x4F7F;&#x7528;&#x4E86;json.Unmarshal&#x51FD;&#x6578;&#x4F86;&#x5C07;JSON&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x89E3;&#x78BC;&#x7232;&#x5B57;&#x7BC0;slice&#x3002;&#x4F46;&#x662F;&#x9019;&#x500B;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x5011;&#x4F7F;&#x7528;&#x4E86;&#x57FA;&#x65BC;&#x6D41;&#x5F0F;&#x7684;&#x89E3;&#x78BC;&#x5668;json.Decoder&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5F9E;&#x4E00;&#x500B;&#x6D41;&#x89E3;&#x78BC;JSON&#x6578;&#x64DA;&#xFF0C;&#x76E1;&#x7BA1;&#x9019;&#x4E0D;&#x662F;&#x5FC5;&#x9B1A;&#x7684;&#x3002;&#x5982;&#x60A8;&#x6240;&#x6599;&#xFF0C;&#x9084;&#x6709;&#x4E00;&#x500B;&#x91DD;&#x5C0D;&#x8F38;&#x51FA;&#x6D41;&#x7684;json.Encoder&#x7DE8;&#x78BC;&#x5C0D;&#x8C61;&#x3002;</p>
<p>&#x6211;&#x5011;&#x8ABF;&#x7528;Decode&#x65B9;&#x6CD5;&#x4F86;&#x586B;&#x5145;&#x8B8A;&#x91CF;&#x3002;&#x9019;&#x91CC;&#x6709;&#x591A;&#x7A2E;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x683C;&#x5F0F;&#x5316;&#x7D50;&#x69CB;&#x3002;&#x4E0B;&#x9762;&#x662F;&#x6700;&#x7C21;&#x55AE;&#x7684;&#x4E00;&#x7A2E;&#xFF0C;&#x4EE5;&#x4E00;&#x500B;&#x56FA;&#x5B9A;&#x5BEC;&#x5EA6;&#x6253;&#x5370;&#x6BCF;&#x500B;issue&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x4E0B;&#x4E00;&#x7BC0;&#x6211;&#x5011;&#x5C07;&#x770B;&#x5230;&#x5982;&#x679C;&#x5229;&#x7528;&#x6A21;&#x95C6;&#x4F86;&#x8F38;&#x51FA;&#x8907;&#x96DC;&#x7684;&#x683C;&#x5F0F;&#x3002;</p>
<pre><code class="lang-Go">gopl.io/ch4/issues
<span class="hljs-comment">// Issues prints a table of GitHub issues matching the search terms.</span>
<span class="hljs-keyword">package</span> main
<span class="hljs-keyword">import</span> (
<span class="hljs-string">&quot;fmt&quot;</span>
<span class="hljs-string">&quot;log&quot;</span>
<span class="hljs-string">&quot;os&quot;</span>
<span class="hljs-string">&quot;gopl.io/ch4/github&quot;</span>
)
<span class="hljs-keyword">func</span> main() {
result, err := github.SearchIssues(os.Args[<span class="hljs-number">1</span>:])
<span class="hljs-keyword">if</span> err != <span class="hljs-constant">nil</span> {
log.Fatal(err)
}
fmt.Printf(<span class="hljs-string">&quot;%d issues:\n&quot;</span>, result.TotalCount)
<span class="hljs-keyword">for</span> _, item := <span class="hljs-keyword">range</span> result.Items {
fmt.Printf(<span class="hljs-string">&quot;#%-5d %9.9s %.55s\n&quot;</span>,
item.Number, item.User.Login, item.Title)
}
}
</code></pre>
<p>&#x901A;&#x904E;&#x547D;&#x4EE4;&#x884C;&#x53C3;&#x6578;&#x6307;&#x5B9A;&#x6AA2;&#x7D22;&#x689D;&#x4EF6;&#x3002;&#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#x662F;&#x67FB;&#x8A62;Go&#x8A9E;&#x8A00;&#x9805;&#x76EE;&#x4E2D;&#x548C;JSON&#x89E3;&#x78BC;&#x76F8;&#x95DC;&#x7684;&#x554F;&#x984C;&#xFF0C;&#x9084;&#x6709;&#x67FB;&#x8A62;&#x8FD4;&#x8FF4;&#x7684;&#x7D50;&#x679C;&#xFF1A;</p>
<pre><code>$ go build gopl.io/ch4/issues
$ ./issues repo:golang/go is:open json decoder
13 issues:
#5680 eaigner encoding/json: set key converter on en/decoder
#6050 gopherbot encoding/json: provide tokenizer
#8658 gopherbot encoding/json: use bufio
#8462 kortschak encoding/json: UnmarshalText confuses json.Unmarshal
#5901 rsc encoding/json: allow override type marshaling
#9812 klauspost encoding/json: string tag not symmetric
#7872 extempora encoding/json: Encoder internally buffers full output
#9650 cespare encoding/json: Decoding gives errPhase when unmarshalin
#6716 gopherbot encoding/json: include field name in unmarshal error me
#6901 lukescott encoding/json, encoding/xml: option to treat unknown fi
#6384 joeshaw encoding/json: encode precise floating point integers u
#6647 btracey x/tools/cmd/godoc: display type kind of each named type
#4237 gjemiller encoding/base64: URLEncoding padding is optional
</code></pre><p>GitHub&#x7684;Web&#x670D;&#x52D9;&#x63A5;&#x53E3; <a href="https://developer.github.com/v3/" target="_blank">https://developer.github.com/v3/</a> &#x5305;&#x542B;&#x4E86;&#x66F4;&#x591A;&#x7684;&#x7279;&#x6027;&#x3002;</p>
<p><strong>&#x7DF4;&#x7FD2; 4.10&#xFF1A;</strong> &#x8129;&#x6539;issues&#x7A0B;&#x5E8F;&#xFF0C;&#x6839;&#x64DA;&#x554F;&#x984C;&#x7684;&#x6642;&#x9593;&#x9032;&#x884C;&#x5206;&#x985E;&#xFF0C;&#x6BD4;&#x5982;&#x4E0D;&#x5230;&#x4E00;&#x500B;&#x6708;&#x7684;&#x3001;&#x4E0D;&#x5230;&#x4E00;&#x5E74;&#x7684;&#x3001;&#x8D85;&#x904E;&#x4E00;&#x5E74;&#x3002;</p>
<p><strong>&#x7DF4;&#x7FD2; 4.11&#xFF1A;</strong> &#x7DE8;&#x5BEB;&#x4E00;&#x500B;&#x5DE5;&#x5177;&#xFF0C;&#x5141;&#x8A31;&#x7528;&#x6236;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x5275;&#x5EFA;&#x3001;&#x8B80;&#x53D6;&#x3001;&#x66F4;&#x65B0;&#x548C;&#x522A;&#x9664;GitHub&#x4E0A;&#x7684;issue&#xFF0C;&#x7576;&#x5FC5;&#x8981;&#x7684;&#x6642;&#x5019;&#x81EA;&#x52D5;&#x6253;&#x958B;&#x7528;&#x6236;&#x9ED8;&#x8A8D;&#x7684;&#x7DE8;&#x8F2F;&#x5668;&#x7528;&#x65BC;&#x8F38;&#x5165;&#x6587;&#x672C;&#x4FE1;&#x606F;&#x3002;</p>
<p><strong>&#x7DF4;&#x7FD2; 4.12&#xFF1A;</strong> &#x6D41;&#x884C;&#x7684;web&#x6F2B;&#x7575;&#x670D;&#x52D9;xkcd&#x4E5F;&#x63D0;&#x4F9B;&#x4E86;JSON&#x63A5;&#x53E3;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x4E00;&#x500B; <a href="https://xkcd.com/571/info.0.json" target="_blank">https://xkcd.com/571/info.0.json</a> &#x8ACB;&#x6C42;&#x5C07;&#x8FD4;&#x8FF4;&#x4E00;&#x500B;&#x5F88;&#x591A;&#x4EBA;&#x559C;&#x611B;&#x7684;571&#x7DE8;&#x865F;&#x7684;&#x8A73;&#x7D30;&#x63CF;&#x8FF0;&#x3002;&#x4E0B;&#x8F09;&#x6BCF;&#x500B;&#x93C8;&#x63A5;&#xFF08;&#x96BB;&#x4E0B;&#x8F09;&#x4E00;&#x6B21;&#xFF09;&#x7136;&#x5F8C;&#x5275;&#x5EFA;&#x4E00;&#x500B;&#x96E2;&#x7DDA;&#x7D22;&#x5F15;&#x3002;&#x7DE8;&#x5BEB;&#x4E00;&#x500B;xkcd&#x5DE5;&#x5177;&#xFF0C;&#x4F7F;&#x7528;&#x9019;&#x4E9B;&#x96E2;&#x7DDA;&#x7D22;&#x5F15;&#xFF0C;&#x6253;&#x5370;&#x548C;&#x547D;&#x4EE4;&#x884C;&#x8F38;&#x5165;&#x7684;&#x6AA2;&#x7D22;&#x8A5E;&#x76F8;&#x5339;&#x914D;&#x7684;&#x6F2B;&#x7575;&#x7684;URL&#x3002;</p>
<p><strong>&#x7DF4;&#x7FD2; 4.13&#xFF1A;</strong> &#x4F7F;&#x7528;&#x958B;&#x653E;&#x96FB;&#x5F71;&#x6578;&#x64DA;&#x5EAB;&#x7684;JSON&#x670D;&#x52D9;&#x63A5;&#x53E3;&#xFF0C;&#x5141;&#x8A31;&#x4F60;&#x6AA2;&#x7D22;&#x548C;&#x4E0B;&#x8F09; <a href="https://omdbapi.com/" target="_blank">https://omdbapi.com/</a> &#x4E0A;&#x96FB;&#x5F71;&#x7684;&#x540D;&#x5B57;&#x548C;&#x5C0D;&#x61C9;&#x7684;&#x6D77;&#x5831;&#x5716;&#x50CF;&#x3002;&#x7DE8;&#x5BEB;&#x4E00;&#x500B;poster&#x5DE5;&#x5177;&#xFF0C;&#x901A;&#x904E;&#x547D;&#x4EE4;&#x884C;&#x8F38;&#x5165;&#x7684;&#x96FB;&#x5F71;&#x540D;&#x5B57;&#xFF0C;&#x4E0B;&#x8F09;&#x5C0D;&#x61C9;&#x7684;&#x6D77;&#x5831;&#x3002;</p>
2015-12-09 07:57:17 +00:00
</section>
</div>
</div>
</div>
<a href="../ch4/ch4-04.html" class="navigation navigation-prev " aria-label="Previous page: 結構體"><i class="fa fa-angle-left"></i></a>
<a href="../ch4/ch4-06.html" class="navigation navigation-next " aria-label="Next page: 文本和HTML模闆"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="../gitbook/app.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
<script>
require(["gitbook"], function(gitbook) {
2015-12-28 08:08:26 +00:00
var config = {"katex":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
2015-12-09 07:57:17 +00:00
gitbook.start(config);
});
</script>
</body>
</html>