【问题标题】:How to use the response in a SAP Netweaver gateway HTTP Adapter?如何在 SAP Netweaver 网关 HTTP 适配器中使用响应?
【发布时间】:2015-05-22 11:25:11
【问题描述】:

我正在使用 SAP Netweaver Gateway HTTP 适配器集成 SAP 和 IBM MobileFirst。 我能够成功连接到 SAP 后端系统,并且我正在获取 xml 格式的数据。这是我得到的回复:

{
"RETURN": "<?xml version=\"1.0\" encoding=\"utf-8\"?><app:service xml:base=\"http:\/\/sapecc.mss.com:8000\/sap\/opu\/sdata\/iwfnd\/SampleUserProcessing\/\" xmlns:app=\"http:\/\/www.w3.org\/2007\/app\" xmlns:atom=\"http:\/\/www.w3.org\/2005\/Atom\" xmlns:sap=\"http:\/\/www.sap.com\/Protocols\/SAPData\" xmlns:gp=\"http:\/\/www.sap.com\/Protocols\/SAPData\/GenericPlayer\" xmlns:m=\"http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/metadata\"><app:workspace sap:semantics=\"things\"><atom:title>Things<\/atom:title><\/app:workspace><app:workspace sap:semantics=\"data\"><atom:title>Data<\/atom:title><app:collection href=\"RoleCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>RoleCollection<\/atom:title><sap:member-title>Role<\/sap:member-title><\/app:collection><app:collection href=\"ImageCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>ImageCollection<\/atom:title><sap:member-title>Image<\/sap:member-title><\/app:collection><app:collection href=\"EmailCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>EmailCollection<\/atom:title><sap:member-title>Email<\/sap:member-title><\/app:collection><app:collection href=\"ActivitygroupCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>ActivitygroupCollection<\/atom:title><sap:member-title>Activitygroup<\/sap:member-title><\/app:collection><app:collection href=\"UserCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>UserCollection<\/atom:title><sap:icon>icon<\/sap:icon><sap:member-title>User<\/sap:member-title><atom:link href=\"SubscriptionCollection\" rel=\"http:\/\/www.sap.com\/Protocols\/SAPData\/rel#subscribe\"\/><\/app:collection><app:collection href=\"UserXnotificationCollection\" sap:creatable=\"false\" sap:updatable=\"false\" sap:deletable=\"false\"><atom:title>UserxnotificationCollection<\/atom:title><sap:member-title>UserXnotification<\/sap:member-title><\/app:collection><app:collection href=\"SubscriptionCollection\" sap:semantics=\"subscriptions\" sap:creatable=\"true\" sap:updatable=\"false\" sap:deletable=\"true\"><atom:title>Subscriptions<\/atom:title><sap:icon>\/sap\/public\/opu\/resources\/sap\/iwfnd\/subscription\/icon_subscription.png<\/sap:icon><sap:member-title>Subscription<\/sap:member-title><gp:collectionLayout display-order=\"1000\" top-level=\"true\"\/><\/app:collection><\/app:workspace><app:workspace sap:semantics=\"subscriptions&amp;notifications\"><atom:title>Subscriptions &amp; Notifications<\/atom:title><\/app:workspace><\/app:service>",
    "isSuccessful": true,
    "responseHeaders": {
      "content-type": "application\/xml",
      "dataserviceversion": "2.0",
      "server": "SAP NetWeaver Application Server \/ ABAP 731",
      "x-sap-odata-extension-version": "0.9;gp=0.8"
    },
    "statusCode": 200,
    "statusReason": "OK"
    }

现在我想从 xml 中选择一个特定的值。任何人都可以在这方面帮助我吗?

function retrieveTravelAgencyProperty() {
var request = {
    CollectionName: "SampleUserProcessing",

};
return WL.Server.fetchNWBusinessObject(request);
}

【问题讨论】:

    标签: javascript json xml ibm-mobilefirst mobilefirst-adapters


    【解决方案1】:

    所以回到您的客户端逻辑,在适配器调用的成功回调中,您将获得一个 JSON 对象。此 JSON 对象包含响应。

    所以我认为你应该做的是:

    1. 要么提取到另一个变量,要么直接处理响应中的“RETURN”键和
    2. 再次将其转换为可读的 JSON 格式,如下所示:http://davidwalsh.name/convert-xml-json
    3. 遍历刷新的响应以找到您要查找的键:值。例如:

      for (i = 0; i < resultSet.length; i++) {
          if (resultSet[i].name == "some-value") { // assumed that you know what you're lookign for.
              alert (resultSet[i].name);
      }
      

    第 2 步是困难的部分...不确定。

    【讨论】:

    • 默认情况下,我在创建 Adapter 时得到了此代码,这里我们没有了解如何使用此键解析该 xml 响应 /*code*/ var request = { CollectionName: "TravelAgencies", Keys : [{Name: "TravelAgencyID", value: parameters.keys.TravelAgencyID}, ], Select: parameters.select || [],展开:参数。展开 || [] };
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多