<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## 標識符 ### omitempty 為空不顯示 添加`omitempty`后,如果 data 為空,則不顯示 data 如 0 ,"",flase 等都為空值 ``` type H struct{ Msg string `json:"msg"` Data interface{} `json:"data,omitempty"` } ``` `{"name":"asd"}` ### - 過濾都該字段的序列化 ``` type H struct{ Msg string `json:"msg"` Data interface{} `json:"-"` } ``` `{"name":"asd"}` ### 指定序列化格式,可讓 int 轉為 string ``` type User struct { Name string `json:"name"` Age int8 `json:"age,string"` } ``` `{"name":"asd","age":"123"}` ## json.Marshal ``` type ColorGroup struct { ID int Name string Colors []string } group := ColorGroup{ ID: 1, Name: "Reds", Colors: []string{"Crimson", "Red", "Ruby", "Maroon"}, } b, err := json.Marshal(group) if err != nil { fmt.Println("error:", err) } fmt.Printf("%+v\n", string(b)) // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]} ``` ## json.Unmarshal ``` var jsonBlob = []byte(`[ {"Name": "Platypus", "Order": "Monotremata"}, {"Name": "Quoll", "Order": "Dasyuromorphia"} ]`) type Animal struct { Name string Order string } var animals []Animal err := json.Unmarshal(jsonBlob, &animals) if err != nil { fmt.Println("error:", err) } fmt.Printf("%+v", animals) // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}] ``` ### json.Indent 縮進json ``` var jsonBlob = []byte(`[ {"Name": "Platypus", "Order": "Monotremata"}, {"Name": "Quoll", "Order": "Dasyuromorphia"} ]`) var a bytes.Buffer err := json.Indent(&a, jsonBlob, "", " ") if err != nil { panic(err) } fmt.Printf("%+v\n", a.String()) /* [ { "Name": "Platypus", "Order": "Monotremata" }, { "Name": "Quoll", "Order": "Dasyuromorphia" } ] */ ``` ## json.HTMLEscape ``` var out bytes.Buffer json.HTMLEscape(&out, []byte(`{"Name":"<b>HTML content</b>"}`)) out.WriteTo(os.Stdout) // Output: //{"Name":"\u003cb\u003eHTML content\u003c/b\u003e"} ``` ## json.NewDecoder 有雜質信息也可序列化 ``` type User struct { UserName string `json:"username"` Password string `json:"password"` } jsonString := `{ "username": "foobar@example.com", "password": "YOUR PASSWORD" }otherinfo` str := strings.NewReader(jsonString) // io.Reader usr := User{} err := json.NewDecoder(str).Decode(&usr) if err != nil { log.Fatalf("Decode failed, %#v\n", err) } log.Printf("User %#v\n", usr)//User main.User{UserName:"foobar@example.com", Password:"YOUR PASSWORD"} ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看