加载 JSON 文件
您刚加入一家电商分析团队,第一项任务是探索公司的商品目录。数据以 JSON 文件的形式提供——在处理 Web API 和现代数据源时,您会经常遇到这种格式。
在开始分析之前,您需要先加载 JSON 数据并了解其结构。JsonReader、JsonReadOptions 和 Table 类已为您导入。
本练习是课程的一部分
Java 中的数据导入
练习说明
- 为该文件配置并构建 JSON 读取选项。
- 创建一个
JsonReader并将数据加载到表中。 - 显示该表的前三行。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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));
}
}