標籤:
第一部分需要三個步驟:
選擇輸入步驟,“產生記錄”,將步驟裡設定記錄數為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;
}
最後,確認前面的步驟無誤後,選擇步驟表輸出:
kettle HTTP client