可用版本: Dev (3.21) | 最新 (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11

导入 JSON

适用于 ✅ 开源版   ✅ 专业版   ✅ 企业版

下面的 JSON 数据表示两个作者记录,这些记录可能先前已通过 jOOQ 的 导出功能导出。

{"fields" :[{"name":"ID","type":"INTEGER"},
            {"name":"AUTHOR_ID","type":"INTEGER"},
            {"name":"TITLE","type":"VARCHAR"}],
 "records":[[1,1,"1984"],
            [2,1,"Animal Farm"]]}

以下示例展示了如何映射源数据和目标表。

// Specify fields from the target table to be matched with fields from the source JSON array by position.
// Positional matching is independent of the presence of a header information in the JSON content.
create.loadInto(BOOK)
      .loadJSON(inputstream, encoding)
      .fields(BOOK.ID, BOOK.AUTHOR_ID, BOOK.TITLE)
      .execute();

// Use "null" field placeholders to ignore source columns by position.
create.loadInto(BOOK)
      .loadJSON(inputstream, encoding)
      .fields(BOOK.ID, null, BOOK.TITLE)
      .execute();

// Match target fields with source fields by "corresponding" name.
// This assumes that JSON content contains header information as exported by jOOQ
create.loadInto(BOOK)
      .loadJSON(inputstream, encoding)
      .fieldsCorresponding()
      .execute();

目前没有其他特定于 JSON 的选项可用。

反馈

您对此页面有任何反馈吗? 我们很乐意倾听!

The jOOQ Logo