我正在尝试执行一个从服务器站点检索一组信息的编排,并且我想操纵输出以便仅获取必要的数据。
输出的操作菜单,允许我通过 Groovy 编码来处理它。
未经处理的输出会引发如下 JSON:
{
"formId": "P43081_W43081A",
"gridId": "1",
"title": "Work With Orders Awaiting Approval",
"rowset": [
{
"P43081_AN8_Originator": "304565",
"P43081_DL01_Supplier": "I.T. Laptop/Tablets",
"P43081_AN8_Supplier": "533104",
},
{
"P43081_AN8_Originator": "304565",
"P43081_DL01_Supplier": "I.T. Laptop/Tablets",
"P43081_AN8_Supplier": "533104",
},
{
"P43081_AN8_Originator": "304565",
"P43081_DL01_Supplier": "Office Plus Supplies",
"P43081_AN8_Supplier": "533103",
}
],
"records": 3,
"moreRecords": false
}
我只需要行集级别的信息。为了做到这一点,我操纵了包括以下代码的输出:
import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;
import com.oracle.e1.common.OrchestrationAttributes;
String main(OrchestrationAttributes orchAttr, String input)
{
def jsonIn = new JsonSlurper().parseText(input);
// modify jsonIn;
def jsonOut = new JsonBuilder(jsonIn.rowset);
// orchAttr.writeWarn("custom log entry - warning");
// orchAttr.writeDebug("custom log entry - debug");
return jsonOut;
}
这给我带来了以下错误:
“消息”:“com.fasterxml.jackson.databind.node.ArrayNode 无法转换为 com.fasterxml.jackson.databind.node.ObjectNode”
我推断错误原因是因为我作为 JsonBuilder 参数传递了一个数组对象(行集)而不是一个对象。
您知道如何处理输出并将正确格式的参数传递给 JsonBuilder 吗?
我想得到的输出是:
{
"P43081_AN8_Originator": "304565",
"P43081_DL01_Supplier": "I.T. Laptop/Tablets",
"P43081_AN8_Supplier": "533104",
},
{
"P43081_AN8_Originator": "304565",
"P43081_DL01_Supplier": "I.T. Laptop/Tablets",
"P43081_AN8_Supplier": "533104",
},
{
"P43081_AN8_Originator": "304565",
"P43081_DL01_Supplier": "Office Plus Supplies",
"P43081_AN8_Supplier": "533103",
}