【问题标题】:Maximo Automation Script for Integration - JSON用于集成的 Maximo 自动化脚本 - JSON
【发布时间】:2020-10-20 07:48:01
【问题描述】:

我正在编写一个集成脚本来修改 JSON 输入并保存到 maximo。首先,我将 StructureData erData 输入转换为 JSON 对象,如下所示;

var resp = JSON.parse(erData.getDataAsString());

然后我修改了 JSON 对象以添加其他属性。如何将修改后的 JSON 对象转换回 StructureData erData,以便将其保存到 Maximo。

谢谢。问候

【问题讨论】:

  • 顺便说一句,Maximo 中的 JSON 映射应用程序可能允许您在不需要代码的情况下执行相同的操作,具体取决于您所做的事情的复杂程度。
  • 您可以通过显示更多代码来提高问题的质量。您可以通过使用通用名称和/或值来保护您的隐私,但如果您提供 minimal reproducible example,它将帮助我们帮助您并帮助您的问题使其他用户受益。

标签: javascript integration maximo


【解决方案1】:

使用JSON.stringify() javaScript 方法将修改后的 JSON 对象转换回 StructureData erData,如下所示:

,您的resp 有以下字符串化数据:'{"result":true, "count":42}'

var resp = JSON.parse(erData.getDataAsString());  // resp = '{"result":true, "count":42}';
resp['name'] = 'Dummy';                           // a new property with key name and value Dummy is created and added in resp
console.log(resp);                                // you get the new resp object
console.log(JSON.stringify(resp));                // '{"result":true, "count":42, "name":"Dummy"}'

如果 Maximo 工作,请关注JSON String from JSON Object Maximo

希望对你有帮助!!

【讨论】:

  • 是的,我之前做过。不幸的是,maximo 无法处理它,因为它被读取为字符串类型。这是错误:“java.lang.String 与 psdi.iface.mic.StructureData 不兼容”
【解决方案2】:

查看 Maximo JavaDocs 的 StructureData,但不确定它有多彻底,您可以尝试 StructureData(JSON.stringify(resp))。如果这不起作用,您可能需要将 JSON 转换为 XML,并将 XML 作为字节数组传递给 StructureData 构造函数。

或者,使用StructureData 方法直接操作erData,无需转换为JSON。

【讨论】:

    猜你喜欢
    • 2018-08-18
    • 2020-09-24
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多