亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 apache Velocity 進行 JSON 到 JSON 轉換?有沒有更好的方法來編寫我在

使用 apache Velocity 進行 JSON 到 JSON 轉換?有沒有更好的方法來編寫我在

慕的地8271018 2022-09-28 14:24:28
我正在使用apache速度進行json轉換。下面是我的 json 字符串    {    "apiCode": "Payment Execution Service",    "name": "Initiate a payment",    "description": "Initiate a payment",    "request": {        "method": "POST",        "path": "/api/v1/payments",        "headers": [            {                "Corporate-ID": "apiKey"            },            {                "Content-Type": "application/json"            }        ],        "body": "{\n  \"beneficiaryInformation\" : {\n    \"destinationAccountIdentifier\" : \"string\",\n    \"destinationBankIdentifier\" : \"DEUTDEDB237\",\n    \"fullName\" : \"JASON SMITH\"\n  },\n  \"purposeOfPayment\" : \"Invoice Payment\",\n  \"remittanceInformation\" : \"Mantainance of Fixtures\",\n  \"remitterInformation\" : {\n    \"sourceAccountCurrency\" : \"EUR\",\n    \"sourceAccountIdentifier\" : \"string\",\n    \"sourceBankIdentifier\" : \"DEUTDEDBFRA\"\n  },\n  \"transferAmount\" : 1.5,\n  \"transferCurrency\" : \"EUR\",\n  \"transferDate\" : \"2015-07-20\",\n  \"transferType\" : \"SCTInst\",\n  \"uniqueRequestNo\" : \"string\"\n}"    },    "response": {        "status": 200,        "headers": [            {                "Content-Type": "application/json"            }        ],        "body": "{\n  \"requestReferenceNo\" : \"string\",\n  \"transactionStatus\" : {\n    \"bankReferenceNo\" : \"string\",\n    \"reasonCode\" : \"string\",\n    \"statusCode\" : \"string\"\n  }\n}"    },    "provider": "Payment Execution Service"}下面是我的 .vm 文件   {"provider": {    "name": "$arr[0].apiCode"},"consumer": {    "name": "$arr[0].provider"},"interactions": [#set($i = 0)#foreach($a in $arr) {        "description": "$a.description",        "request": {            "path": "$a.request.path",            "method": "$a.request.method",            "headers": $json.valueToString($a.request.headers),            "body": $json.valueToString($a.request.body)        },
查看完整描述

1 回答

?
ITMISS

TA貢獻1871條經驗 獲得超8個贊

問題出在以下行中:

JSONObject responseobj = new JSONObject(obj.get("response").toString());

你把 是作為字符串到 JSON 對象,這就是為什么它以這種方式工作。


查看完整回答
反對 回復 2022-09-28
  • 1 回答
  • 0 關注
  • 213 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號