将对象参数传递给采用javascribt对象

时间:2015-08-18 10:54:48

标签: ios swift ibm-mobilefirst

我正在使用与Worklight服务器集成的原生iOS Swift应用程序,我遇到的问题是在适配器上将对象“params”作为参数,并且此对象是一个javascript对象,但是当我试图从我的原生应用程序调用此适配器时,服务器不断给出缺少参数的响应,这是一个代码片段:

let procedure = WLProcedureInvocationData(adapterName: adapterNameTextField.text, procedureName: procedureNameTextField.text)

procedure.parameters = ["en","firas@cloudappers.com","123123123"]

WLClient.sharedInstance().invokeProcedure(procedure, withDelegate: ProcedureDelegate(master: self))

这是适配器的过程标题:

function findCardKey(language,userId,params) {

    var request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="..." xmlns:xs1="....">'
        +getHeader(language,userId)
        +'<soapenv:Body>'
            +'<xs1:findCardKeyRequest>'
                +jsonToXml(params,'', null) 
            +'</xs1:findCardKeyRequest>'
        +'</soapenv:Body>'
    +'</soapenv:Envelope>';

    var result = invokeWebService(request,"findCardKey");

    return result;

}

此params是一个javascript对象,其中包含名为“tagId”的属性。

这是在CardEnquiryServiceModel中的混合应用中调用的地方:

findCardKey: function(parameters, callback, userId) 
{
    var invocationData = 
    {
        adapter: 'nolCardEnquiryv2Service',
        procedure: 'findCardKey',
        parameters: [GeneralUtil.getServerLanguage(), userId, parameters]
    };

    InvokeUtil.invokeProcedure(invocationData, null, callback);

}

以下是使用它的地方:

var parameters = {};
parameters.tagId = $("#tagIdInput").val();
CardEnquiryServiceModel.findCardKey(parameters, _this.getCardEnquiryServiceFindCardKeyResult, user_id);

我应该使用什么形式或类型或方式将此对象传递给iOS Swift中的适配器?

1 个答案:

答案 0 :(得分:0)

您需要将数据放在字典中:

let myDictionary = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]

然后将其添加到invocationData:

invocationData.parameters = ["en","firas@cloudappers.com",myDictionary]

一切都在一起,例如:

let myDictionary = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]
let invocationData = WLProcedureInvocationData(adapterName: "RSSReader", procedureName: "getStories")
invocationData.parameters = ["en","firas@cloudappers.com",myDictionary]
WLClient.sharedInstance().invokeProcedure(invocationData, withDelegate: invokeListener)

在适配器代码中,确保JSON.stringify它。例如:

function getStories(language, email, params) {
    WL.Logger.info("language: " + language + ", " + "email: " + email + ", " + "params: " + JSON.stringify(params));
    ...
    ... 
    ...
}