JSON 在 WSO2 EI Outlook 连接器中解析错误
JSON Parsing ERROR in WSO2 EI Outlook Connector
我正在尝试做一些简单的脚本,它实际上连接了多个值,其中 json 对象也通过使用 WSO2 EI 6.5.0 包含。
传入有效负载:
{"Company":"Grupo Bimbo DSDE","Description":"Test SR","Priority":"P4Low","Short Description":"Test SR","Ticket Type ":"Service Request","Configuration Item":""}
WSO2 脚本中介:
<script language="js"><![CDATA[var log = mc.getServiceLog();
log.info("Logging inside Script Mediator");
var testTicketNo=mc.getProperty("DummyTicketNo");
var Incomingpayload=mc.getProperty("Incomingpayload");
//log.info("Incomingpayload::" + Incomingpayload);
var emailcontent="Hi Team<br/><br/> The requested Ticket Creation Done.. and the Created Ticker No is: " + testTicketNo + "<br/><br/> Below is the request Data for your reference...<br/><br/>" + JSON.parse(Incomingpayload)+ "<br/> Let us know if you have any queries.. <br/><br/>Cheers<br/> WSO2 Team";
//log.info("emailcontent is==" + String(emailcontent));
mc.setProperty('content',emailcontent.toString());]]></script>
以上脚本的输出:
Hi Team<br/><br/> The requested Ticket Creation Done.. and the Created Ticker No is: TestSR2506005<br/><br/> Below is the request Data for your reference...<br/><br/>{"Company":"Grupo Bimbo DSDE","Description":"Test SR","Priority":"P4Low","Short Description":"Test SR","Ticket Type ":"Service Request","Configuration Item":""}<br/> Let us know if you have any queries.. <br/><br/>Cheers<br/> WSO2 Team
我正在使用以上内容通过WSO2 Outlook connector发送电子邮件。
在上面的预定义连接器中,JSON结构如下所示。
{
"Message":
{
"ToRecipients":,
"Body":
{
"ContentType": "",
"Content": ""
}
}
}
最后,我在 $3 中使用了这个串联的字符串内容。上面预定义的有效负载不接受我的字符串内容($3 是自动连接字符串的地方),我希望将字符串与 Json 一起放置会导致这里出现问题。
错误:
[2021-07-13 15:16:20,596] [] ERROR - ScriptMediator The script engine returned an error executing the inlined js script function mediate
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.WrappedException: Wrapped com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EvaluatorException: missing } after property list (<Unknown source>#1) in <Unknown source> at line number 1 (<Unknown Source>#27) in <Unknown Source> at line number 27
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
如果我更正此JSON 解析,电子邮件将成功发送。
是否有任何提示可以转义此 Json字符串内容中的对象?
提前致谢。
嗯,你不能在 wso2 中将非转义的 "
(引号)放在另一个 JSON 中。 TryInstead 而不是使用:JSON.parse(Incomingpayload)
,只是 +Incomingpayload+
或 +Incomingpayload.toString()+
应该生成带有转义引号的 JSON。
作为替代方案,您也可以尝试 +JSON.stringify(Incomingpayload)+
,但这只适用于:
<script language="nashornJs">
我正在尝试做一些简单的脚本,它实际上连接了多个值,其中 json 对象也通过使用 WSO2 EI 6.5.0 包含。
传入有效负载:
{"Company":"Grupo Bimbo DSDE","Description":"Test SR","Priority":"P4Low","Short Description":"Test SR","Ticket Type ":"Service Request","Configuration Item":""}
WSO2 脚本中介:
<script language="js"><![CDATA[var log = mc.getServiceLog();
log.info("Logging inside Script Mediator");
var testTicketNo=mc.getProperty("DummyTicketNo");
var Incomingpayload=mc.getProperty("Incomingpayload");
//log.info("Incomingpayload::" + Incomingpayload);
var emailcontent="Hi Team<br/><br/> The requested Ticket Creation Done.. and the Created Ticker No is: " + testTicketNo + "<br/><br/> Below is the request Data for your reference...<br/><br/>" + JSON.parse(Incomingpayload)+ "<br/> Let us know if you have any queries.. <br/><br/>Cheers<br/> WSO2 Team";
//log.info("emailcontent is==" + String(emailcontent));
mc.setProperty('content',emailcontent.toString());]]></script>
以上脚本的输出:
Hi Team<br/><br/> The requested Ticket Creation Done.. and the Created Ticker No is: TestSR2506005<br/><br/> Below is the request Data for your reference...<br/><br/>{"Company":"Grupo Bimbo DSDE","Description":"Test SR","Priority":"P4Low","Short Description":"Test SR","Ticket Type ":"Service Request","Configuration Item":""}<br/> Let us know if you have any queries.. <br/><br/>Cheers<br/> WSO2 Team
我正在使用以上内容通过WSO2 Outlook connector发送电子邮件。
在上面的预定义连接器中,JSON结构如下所示。
{
"Message":
{
"ToRecipients":,
"Body":
{
"ContentType": "",
"Content": ""
}
}
}
最后,我在 $3 中使用了这个串联的字符串内容。上面预定义的有效负载不接受我的字符串内容($3 是自动连接字符串的地方),我希望将字符串与 Json 一起放置会导致这里出现问题。
错误:
[2021-07-13 15:16:20,596] [] ERROR - ScriptMediator The script engine returned an error executing the inlined js script function mediate
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.WrappedException: Wrapped com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EvaluatorException: missing } after property list (<Unknown source>#1) in <Unknown source> at line number 1 (<Unknown Source>#27) in <Unknown Source> at line number 27
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
如果我更正此JSON 解析,电子邮件将成功发送。
是否有任何提示可以转义此 Json字符串内容中的对象?
提前致谢。
嗯,你不能在 wso2 中将非转义的 "
(引号)放在另一个 JSON 中。 TryInstead 而不是使用:JSON.parse(Incomingpayload)
,只是 +Incomingpayload+
或 +Incomingpayload.toString()+
应该生成带有转义引号的 JSON。
作为替代方案,您也可以尝试 +JSON.stringify(Incomingpayload)+
,但这只适用于:
<script language="nashornJs">