第一部分需要三個步驟:
選擇輸入步驟,“生成記錄”,將步驟里設置記錄數為1,並設置一個類型為String的字段country(名字隨便),這個字段的值應設置為我們要抽取數據的URL,如:
然后,添加一個“HTTP 客戶端”步驟,並把這兩個步驟連起來。對於“HTTP 客戶端”來說,選擇“從字段中獲取URL”(Accept URL from field)選項,並選擇country作為URL的來源字段。
選擇文本文件輸出,輸入文件名稱及所需擴展名,選擇內容選項卡並根據需要修改,字段選項卡獲取所需字段。
第二部分需要三個步驟:
選擇“json輸入”,瀏覽並增加文件或路徑,讀取json文件中的內容:
選擇腳本中的“Java代碼”,將解析出來的字段中需要修改或者添加的部分進行必要修改。
private static int count = 0;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
if (first){
first = false;
}
Object[] r = getRow();
if (r == null) {
setOutputDone();
return false;
}
// It is always safest to call createOutputRow() to ensure that your output row's Object[] is large
// enough to handle any new fields you are creating in this step.
r = createOutputRow(r, data.outputRowMeta.size());
if(count== 0){
String num_ID = "0";//get(Fields.In, "num_ID").getString(r);
count = Integer.parseInt(num_ID);
}
get(Fields.In, "num_ID").setValue(r, ++count);
// Send the row on to the next step.
putRow(data.outputRowMeta, r);
return true;
}
最后,確認前面的步驟無誤后,選擇步驟表輸出: