把jar包放到custom jar 目录下
[json-20210307.jar.zip](/wp-content/uploads/2025/07/49381d17f973fba92a115a5de0ade45d.zip)
可以把xml转成成json对象来处理
```
try{
var result = {
}
//读取传入参数
var requestJson = JSON.parse(requestText);
if( typeof(requestJson) === "string" ){
requestJson = JSON.parse(requestJson);
}
var xmlStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<root>"+
"<head>"+
"<busi_resp_code>00000</busi_resp_code>"+
"<busi_resp_msg>交易成功</busi_resp_msg>"+
"<file_flag>0</file_flag>"+
"<gxp_resp_code>00000</gxp_resp_code>"+
"<gxp_resp_msg>交易成功</gxp_resp_msg>"+
"</head>"+
"</root>"
var XML = Java.type("org.json.XML");
var contentJson = XML.toJSONObject(xmlStr);
contentJson = JSON.parse(contentJson.toString());
print("contentJson==="+JSON.stringify(contentJson))
result.type = "success";
result.message = contentJson;
}catch(e){
print(e)
result.type = "error";
result.message = "失败";
result.data = e.name + ": " + e.message
}
this.response.setBody(result,"application/json");
```
返回结果
```json
{
"type": "success",
"message": {
"root": {
"head": {
"busi_resp_msg": "交易成功",
"gxp_resp_msg": "交易成功",
"file_flag": 0,
"gxp_resp_code": "00000",
"busi_resp_code": "00000"
}
}
}
}
```
评论