開始使用免費開始

載入 JSON 檔案

你剛加入一家電商的資料分析團隊,第一個任務是探索公司的產品目錄。資料是以 JSON 檔案提供——當你處理網路 API 和現代資料來源時,這是很常見的格式。

在開始分析之前,你需要先載入 JSON 資料並理解其結構。JsonReaderJsonReadOptionsTable 類別已為你匯入。

本練習屬於課程

Java 中的資料匯入

檢視課程

練習說明

  • 設定並建立該檔案的 JSON 讀取選項。
  • 建立一個 JsonReader,並將資料載入到表格中。
  • 顯示表格的前 3 列。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

public class UnderstandingJSON {
    public static void main(String[] args) {
        // Configure and build JSON read options
        JsonReadOptions options = ____.builder("products.json").____();
        // Create JsonReader and load data
        Table products = new ____().read(____);

        System.out.println("Product Catalog Structure:");
        System.out.println("Columns: " + products.columnNames());
        System.out.println("Row count: " + products.rowCount());
        System.out.println("\nTable structure:");
        System.out.println(products.structure());
        // Display first three rows
        System.out.println("\nFirst few rows:");
        System.out.println(products.____(3));
    }
}
編輯並執行程式碼