<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] # 安裝 ~~~ go get -u github.com/tidwall/sjson ~~~ # 設置值 ~~~ import "github.com/tidwall/sjson" const json = `{"name":{"first":"Janet","last":"Prichard"},"age":47}` func main() { //把name.last的值給改變了 value, _ := sjson.Set(json, "name.last", "Anderson") println(value) } ~~~ 輸出 ~~~ {"name":{"first":"Janet","last":"Anderson"},"age":47} ~~~ # 路徑語法 路徑是由點分隔的一系列鍵。點和冒號字符可以轉義`\` ~~~ { "name": {"first": "Tom", "last": "Anderson"}, "age":37, "children": ["Sara","Alex","Jack"], "fav.movie": "Deer Hunter", "friends": [ {"first": "James", "last": "Murphy"}, {"first": "Roger", "last": "Craig"} ] } ~~~ ~~~ "name.last" >> "Anderson" "age" >> 37 "children.1" >> "Alex" "friends.1.last" >> "Craig" ~~~ 用`-1`鍵可用于將值附加到現有數組: ~~~ "children.-1" >> appends a new value to the end of the children array ~~~ 通常,數字鍵用于修改數組,但可以使用冒號字符強制數字對象鍵: ~~~ { "users":{ "2313":{"name":"Sara"}, "7839":{"name":"Andy"} } } ~~~ 冒號路徑 ~~~ "users.:2313.name" >> "Sara" ~~~ # 支持的類型 ~~~ sjson.Set(`{"key":true}`, "key", nil) sjson.Set(`{"key":true}`, "key", false) sjson.Set(`{"key":true}`, "key", 1) sjson.Set(`{"key":true}`, "key", 10.5) sjson.Set(`{"key":true}`, "key", "hello") sjson.Set(`{"key":true}`, "key", map[string]interface{}{"hello":"world"}) ~~~ 輸出 ~~~ {"key":null} {"key":false} {"key":1} {"key":10.5} {"key":"hello"} {"key":{"hello":"world"}} ~~~ 當一個類型無法識別時,SJSON將回退到`encoding/json`Marshaller # 從空文檔設置一個值 ~~~ value, _ := sjson.Set("", "name", "Tom") println(value) // Output: // {"name":"Tom"} ~~~ # 從空文檔設置嵌套值 ~~~ value, _ := sjson.Set("", "name.last", "Anderson") println(value) // Output: // {"name":{"last":"Anderson"}} ~~~ # 設置新值 ~~~ value, _ := sjson.Set(`{"name":{"last":"Anderson"}}`, "name.first", "Sara") println(value) // Output: // {"name":{"first":"Sara","last":"Anderson"}} ~~~ # 更新現有值 ~~~ value, _ := sjson.Set(`{"name":{"last":"Anderson"}}`, "name.last", "Smith") println(value) // Output: // {"name":{"last":"Smith"}} ~~~ # 設置一個新的數組值 ~~~ value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.2", "Sara") println(value) // Output: // {"friends":["Andy","Carol","Sara"] ~~~ # 使用`-1`路徑中的鍵附加數組值 ~~~ value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.-1", "Sara") println(value) // Output: // {"friends":["Andy","Carol","Sara"] ~~~ # 附加一個超過結尾的數組值 ~~~ value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.4", "Sara") println(value) // Output: // {"friends":["Andy","Carol",null,null,"Sara"] ~~~ # 刪除一個值 ~~~go value, _ := sjson.Delete(`{"name":{"first":"Sara","last":"Anderson"}}`, "name.first") println(value) // Output: // {"name":{"last":"Anderson"}} ~~~ # 刪除一個數組值 ~~~ value, _ := sjson.Delete(`{"friends":["Andy","Carol"]}`, "friends.1") println(value) // Output: // {"friends":["Andy"]} ~~~ # 刪除最后一個數組值 ~~~ value, _ := sjson.Delete(`{"friends":["Andy","Carol"]}`, "friends.-1") println(value) // Output: // {"friends":["Andy"]} ~~~
                  <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>

                              哎呀哎呀视频在线观看