2015-06-15 30 views
0

任何人都可以找到「tenantId」這是在JSON響應的XPath的幫助JSON響應的XPATH下面在soapUI的

{ 
    "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 
     } 

給出如何穿越至「tenantId」?

在此先感謝。

+0

XPath用於選擇XML文檔的某些部分。它具有基本的字符串處理能力,但不會是遍歷JSON數據結構的好工具。如果您告訴我們您希望使用XPath的環境,也許我們可以建議一種更好的方式來處理JSON數據。 – LarsH

回答

3

SoapUI內部將幾乎任何東西都轉換爲XML。您將不得不使用ResponseAsXml屬性。在GUI中,如果你點擊XML標籤,你可以看到這個表示。

類似下面應該工作:

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

非常感謝Siking。 – Bugasur

0

如果你想解決這個使用Groovy,然後由谷歌提供GSON.jar庫擴展SOAPUI。 這個庫專門用於處理JSON對象。

有了這個,你可以很容易地翻譯每個單獨的對象及其屬性值,JSON對象可能有多複雜,是一個很好的附加工作。

+0

我認爲這不是必要的,gdk中的groovy有一個很好的類,可以與Json'一起工作:http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html: )'。 – albciff