REST API 调用后,我有以下格式的 key/value 对,我只需要提取与键对应的特定值

After REST API call ,i have key/value pair in the below format ,I Need to extract just the specific value corresponding to the key

选项 1:如果我使用 TALEND 作业,我会得到 JSON 结果,由于某种原因(无法解析),用反斜杠存储在 JSON 文件中

{"read":[{"Body":"{\"items\":[{\"executionId\":\"a0613a31-d16d-4c4d-9279-4564a86cdd44\",\"startTimestamp\":\"2021-09-15T22:30:26.854Z\",\"triggerTimestamp\":\"2021-09-15T22:30:27.209Z\",\"userId\":\"user1\",\"status\":\"dispatching\",\"runtime{\"type\":\"REMOTE_ENGINE_CLUSTER\"},\"executionStatus\":\"DISPATCHING_FLOW\"},{\"executionId\":\"49a56eb1-f3c7-4f26-9554-8fa88acde38b\",\"startTimestamp\":\"2021-09-15T22:29:15.999Z\",\"triggerTimestamp\":\"2021-09-15T22:29:16.447Z\",\"userId\":\"user1\",\"executionType\":\"MANUAL\",\"status\":\"dispatching\",\"runtime\":{\"type\":\"REMOTE_ENGINE_CLUSTER\"},\"executionStatus\":\"DISPATCHING_FLOW\"}],\"limit\":100,\"offset\":0,\"total\":2}","ERROR_CODE":null}]}

选项2:Using WEB URL: 在 REST API 调用之后,我得到 JSON 结果如下:

BODY:context.statusbody

{
    "items": [{
            "executionId": "4f679c12-d8d7-4dd7-89d5-507a94503988",
            "startTimestamp": "2021-09-14T19:05:01.854Z",
            "triggerTimestamp": "2021-09-14T19:05:02.385Z",
            "userId": "user1",
            "taskId": "60b7f6d31c6e394de0163d35",
            "status": "dispatching",
            "runtime": {
                "type": "REMOTE_ENGINE_CLUSTER"
            },
            "executionStatus": "DISPATCHING_FLOW"
        },
        {
            "executionId": "4f40b04c-1ac1-42ea-9a36-7c25b1b17fe8",
            "startTimestamp": "2021-09-14T19:00:24.769Z",
            "triggerTimestamp": "2021-09-14T19:00:25.122Z",
            "userId": "user1",
            "taskId": "60b7f6d31c6e394de0163d35",
            "executionType": "SCHEDULED",
            "status": "dispatching",
            "runtime": {
                "type": "REMOTE_ENGINE_CLUSTER"
            },
            "executionStatus": "DISPATCHING_FLOW"
        }
    ],
    "limit": 100,
    "offset": 0,
    "total": 2
}

由此我只需要为每次迭代提取 executionID 和 triggerTimestamp 并存储在全局变量中

在我变灰的 tjava3 中,我将全局变量用作:

  context.testexecutionID=((String)globalMap.get("executionID"));
  context.triggerTimestamp=((String)globalMap.get("triggerTimestamp"));
     context.executionID=context.testexecutionID.substring(5, context.testexecutionID.lastIndexOf("\"")-3);
  context.triggerTime=context.triggerTimestamp.substring(5, context.triggerTimestamp.lastIndexOf("\"")-3);

好的,Json我用你的案例来满足你的要求:

请注意,您的 Json 无效

{
    "items": [{
        "executionId": "6e5fa777-9ede-42b9-b862-03b4b1b12375",
        "startTimestamp": "2021-09-15T05:59:40.599Z",
        "triggerTimestamp": "2021-09-15T05:59:41.006Z",
        "userId": "user"
    }],
    "limit ": 100,
    "offset ": 0,
    "total ": 2
}

在不知道你的工作设计的情况下,我只是得到了张贴在这里的输出。

我的工作设计是这样的:

重要!:您的 tFileInputJson 应该像这样获取 2 个字段

如果您想使用 tExtractJSONFields,请使用相同的配置。

储存你的全局变量:

获取 globalVariables 的简单方法是使用 tfixedFlowInput :

输出:

@sarah 根据您在编辑中添加的有效 JSON。

我建议您在 tRest 之后添加以添加 tExtractJSONFields 组件 paremetred:

工作设计应该在第一次测试中:

tRest -> tExtractJSON字段 -> tLogRow .

如果提取良好。第二次测试你必须看到我以前的我的第一个答案才能获得全局变量。