<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Gson 教程 > 原文: [https://howtodoinjava.com/learningpaths/gson/](https://howtodoinjava.com/learningpaths/gson/) 通常,所有現代應用都從遠程服務(例如 [REST](https://restfulapi.net) 或 SOAP)中獲取數據。 數據大部分為 XML 或 JSON 格式。 Gson 自動(在必要時使用簡單的`toJson()`和`fromJson()`方法手動或手動)幫助應用進行 *Java-JSON 序列化和反序列化*。 Gson 可以處理任意 Java 對象,包括我們沒有源代碼的現有對象。 Gson 的最佳**好處是**,在我們為某些成員字段進行非常特定的操作之前,不必強制將注解添加到 Java 類中。 請注意,`Gson`實例在調用 Json 操作時不會保持任何狀態。 因此,您可以自由地將同一對象重用于多個 Json 序列化和反序列化操作。 在本 *Gson 教程*中,我們將學習在我們的應用中有效地使用它。 ## 1\. Gson 基礎知識 在第一部分中,我們將了解 Google Gson 庫及其基本映射功能。 * #### [安裝](https://howtodoinjava.com/gson/gson-installation-maven-gradle-jar/) 學習使用諸如 maven,gradle 或簡單的 jar 文件之類的構建工具在 Java 應用中包括 gson 依賴項。 * #### [簡單序列化和反序列化](https://howtodoinjava.com/gson/gson-serialize-deserialize-json/) 學習如何使用 GSON 將簡單的 Java 對象序列化為 JSON 表示,并將 JSON 字符串反序列化為等效的 Java 對象。 * #### [JSON 輸出格式緊湊型 VS 精美打印](https://howtodoinjava.com/gson/pretty-print-json-output/) Gson 提供的默認 JSON 輸出是緊湊的 JSON 格式。 使用精美打印功能來格式化 JSON 以供讀取。 * #### [數組和對象列表的映射](https://howtodoinjava.com/gson/gson-parse-json-array/) 了解如何使用 Google GSON 庫將包含 json 數組的 JSON 反序列化或解析為 Java 數組或 Java 列表對象。 * #### [集的映射](https://howtodoinjava.com/gson/gson-serialize-deserialize-set/) 了解如何使用 Google GSON 庫反序列化或解析 JSON 以在 Java 中進行設置(例如`HashSet`)。 * #### [映射的映射](https://howtodoinjava.com/gson/gson-serialize-deserialize-hashmap/) 學習使用 Google Gson 庫序列化`HashMap`。 還應學習使用 Gson 將 JSON 字符串反序列化為包含自定義對象的`HashMap`,以便將字段值復制到適當的通用類型中。 ## 2.高級用法 第一部分中的基本示例足以應付默認用例。 我們可能需要自定義 Gson 的行為以支持特定要求。 了解如何執行此操作。 * #### [使用`GsonBuilder`自定義 Gson 對象](https://howtodoinjava.com/gson/gson-gsonbuilder-configuration/) 對于簡單的用例,使用`'Gson gson = new Gson();'`就足夠了。 學習使用 GsonBuilder 通過自定義配置創建新的 Gson 實例。 * #### [序列化空值](https://howtodoinjava.com/gson/serialize-null-values/) 默認情況下,Gson 忽略空值。 學習在序列化和反序列化期間包括空值。 * #### [版本支持](https://howtodoinjava.com/gson/gson-since-version-support/) 可以使用`@Since`注解維護同一對象的多個版本。 Gson 將忽略任何大于配置的版本號的字段/對象。 * #### [使用`@SerializedName`的自定義字段名稱](https://howtodoinjava.com/gson/gson-serializedname/) 了解如何使用 Google GSON 庫將 Java 對象序列化為其 JSON 表示形式,以及將 JSON 字符串反序列化為等效的 Java 對象。 * #### [從序列化和反序列化中排除字段](https://howtodoinjava.com/gson/gson-exclude-or-ignore-fields/) Gson 支持多種機制來排除頂級類,字段和字段類型。 了解如何使用它們。 * #### [`JsonReader` – 流式 JSON 解析器](https://howtodoinjava.com/gson/jsonreader-streaming-json-parser/) 了解如何讀取 JSON 字符串或文件作為 JSON 令牌流。 * #### [`JsonParser`,`JsonElement`和`JsonObject`](https://howtodoinjava.com/gson/gson-jsonparser/) 學習將 JSON 字符串解析或流化為 Java 對象的樹形結構并轉換為`JsonElement`。 * #### [自定義序列化和反序列化](https://howtodoinjava.com/gson/custom-serialization-deserialization/) 學習將 JSON 字符串解析或流化為 Java 對象的樹形結構并轉換為`JsonElement`。 * #### [Gson 教程 - 回顧](https://howtodoinjava.com/gson/google-gson-tutorial/) 讓我們來回顧一下到目前為止我們已經學過的最重要的主題。 請把關于 **gson 教程**的問題交給我。 學習愉快! 參考文獻: [Github 上的 Google Gson](https://github.com/google/gson)
                  <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>

                              哎呀哎呀视频在线观看