xPath of JSON response in soapUI

时间:2015-06-15 14:45:08

标签: json xpath soapui

can anyone help in finding xpath of 'tenantId' which is in JSON response given below

{
   "statusCode": "200",
   "errorParams": null,
   "payLoad":    {
      "UGX:XCD":       {
         "id": 42802,
         "fromCurrency":          {
            "tenantId": "2a610af6-2e42-4a78-8e04-98755e2c6113",
            "code": "UGX",
            "name": "Ugandan Shilling",
            "isoCode": "UGX",
            "active": true,
            "enabled": true,
            "flagModifiedName": false,
            "erpId": null,
            "createdOn": 1427155200000,
            "fieldLibraryStatus": "DRAFT",
            "userId": null
         },
         "toCurrency":          {
            "tenantId": "2a610af6-2e42-4a78-8e04-98755e2c6113",
            "code": "XCD",
            "name": "East Caribbean Dollar",
            "isoCode": "XCD",
            "active": true,
            "enabled": true,
            "flagModifiedName": true,
            "erpId": null,
            "createdOn": 1427155200000,
            "fieldLibraryStatus": "DRAFT",
            "userId": "c7f68b05-044d-44e1-8fc5-0f97a4ece91b"
         },
         "rate": 33,
         "inverseRate": 0.0303,
         "createdOn": 1434025926983,
         "modifiedOn": 1434326400000,
         "active": true,
         "purpose": "cmd",
         "enabled": true,
         "tenantFlag": true,
         "erpId": null
      }

How to traverse till 'tenantId' ??

Thanks in Advance.

2 个答案:

答案 0 :(得分:3)

SoapUI内部将几乎任何内容转换为XML。您必须使用ResponseAsXml属性。在GUI中,如果单击XML选项卡,则可以看到此表示形式。

以下内容应该有效:

${test_step#ResponseAsXml#//*:fromCurrency/*:tenantId}
${test_step#ResponseAsXml#//*:toCurrency/*:tenantId}

答案 1 :(得分:0)

如果您想使用groovy处理此问题,请使用Google提供的GSON.jar库扩展SOAPUI。 这个库是专门为处理JSON对象而编写的。

通过这种方式,您可以轻松地删除每个单独的对象及其属性值,JSON对象可以是多么复杂,这是一个很好的附加组件。