-->

类转换:java.lang.String中不能转换为org.mozilla.javascript.S

2019-10-19 23:36发布

在调用HTTP适配器的过程,它与popsup PROCEDURENAME,签名和PARAMATERS一个对话框,当我输入两个字符串类型的参数后击中运行按钮,我得到“级演员:java.lang.String中不能转换为org.mozilla。 javascript.Scriptable”的错误。

仅供参考,我使用工作灯的应用程序框架的数据对象编辑器创建的工作灯适配器(自动生成的.xml和impl.js文件)

impl.js文件

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



function buildBody(params, namespaces, soapEnvNS){
    var body =
        '<soap:Envelope xmlns:soap="' + soapEnvNS + '">\n' +
        '<soap:Body>\n';

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}

Answer 1:

该错误表明存在一个无效的JSON对象在某处你的代码。

最可能的是该错误提出在使用体转换为字符串body.toString()作为toString将返回[object Object]这是无效的JSON对象值(既不有效也不字符串有效阵列)

使用json.stringify(body)相反,它应该让你究竟想要做的事。

此外,尝试添加一些日志行,以缓解跟踪误差



文章来源: Class Cast: java.lang.String cannot be cast to org.mozilla.javascript.Scriptable