เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การโหลดไฟล์ JSON

สมมติว่าคุณเพิ่งเข้าร่วมทีม e-commerce analytics และงานแรกคือการสำรวจแคตาล็อกสินค้าของบริษัท ข้อมูลมาในรูปแบบไฟล์ JSON ซึ่งเป็นรูปแบบที่พบบ่อยเมื่อทำงานกับ web API และแหล่งข้อมูลสมัยใหม่

ก่อนจะเริ่มวิเคราะห์ ต้องโหลดข้อมูล JSON และทำความเข้าใจโครงสร้างของข้อมูลก่อน โดยได้นำเข้าคลาส JsonReader, JsonReadOptions และ Table ไว้ให้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การนำเข้าข้อมูลใน Java

ดูคอร์ส

คำแนะนำการฝึกหัด

  • กำหนดค่าและ build ตัวเลือกการอ่าน JSON สำหรับไฟล์
  • สร้าง JsonReader และโหลดข้อมูลลงใน table
  • แสดง 3 แถวแรกของ table

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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));
    }
}
แก้ไขและรันโค้ด