## 1、 json格式:會設置 content-type 為 application/json
#### 結構體
```
Type Teacher struct {
Id int
Name string
Age int
}
```
~~~
func (c *OtherController) Get() {
teacher := Teacher{Id: 123, Name: "zhiliao", Age: 2}
c.Data["json"] = teacher //這里必須叫 json, 因為 ServeJSON() 解析 json 變量的
c.ServeJSON()
}
func (c *OtherController) Get() {
teacher := map[string]interface{}{"code":200,"msg":"ok"}
c.Data["json"] = teacher //這里必須叫 json, 因為 ServeJSON() 解析 json 變量的
c.ServeJSON()
}
~~~
## 2、xml格式:會設置 content-type 為 application/xml
#### 結構體
```
Type Person struct {
Id int
Name string
Gender int
}
```
~~~
test_data := Person{Id:123,Name:"zhiliao",Gender:"男"}
g.Data["xml"] = &test_data -----這里必須叫xml,同上
g.ServeXML()
~~~
## 3、jsonp格式:會設置 content-type 為 application/javascript
#### 結構體
```
Type Person struct {
Id int
Name string
Gender int
}
```
~~~
test_data := Person{Id:123,Name:"zhiliao",Gender:"男"}
g.Data["jsonp"] = &test_data -----這里必須叫jsonp,同上
g.ServeJSONP()
~~~