我有一个问题,jsonBuilder从结果字符串中删除引号。如何格式化输出以返回带引号的JSON响应?
import com.eviware.soapui.support.XmlHolder
import net.sf.*
import net.sf.json.*
import net.sf.json.groovy.*
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import groovy.json.*
import groovy.json.JsonOutput
import net.sf.json.JSONObject
def ResponseMessage = testRunner.testCase.testSteps["MerchantEMS_POST"].testRequest.response.contentAsString
def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)
log.info ResponseMessage
def merchantResult = ResponseMessage
def newMerchantID = "60300004055"
def entityID = jsonSlurper.entityId
jsonSlurper.merchantId = newMerchantID
def jsonBuilder = new groovy.json.JsonBuilder()
def updatedjson = jsonBuilder(jsonSlurper)
log.info "updated JSON = $updatedjson"
ResponseMessage :{" entityId" :" 93LSHLXW7BJ5K00MJALWZJMLL0"," creatorId" :" HPCDKMSV763K2VGHCKQQ09QSGM"," createdTimestamp" :" 2015-09-02T00:26:34.015Z"," updaterId" :" HPCDKMSV763K2VGHCKQQ09QSGM"," updatedTimestamp" :" 2015-09-02T00:26:34.015Z"," merchantId" :" L7QWKA0001F5W1RRZY4Z006153", " createdBy" :" ralgg00"," isDeleted" :false}
updatedjson(无引号) = [updatedTimestamp:2015-09-02T00:26:34.015Z,createdBy:ralgg00,createdTimestamp:2015-09-02T00:26:34.015Z,creatorId:HPCDKMSV763K2VGHCKQQ09QSGM ,entityId:93LSHLXW7BJ5K00MJALWZJMLL0,merchantId:60300004055,isDeleted:false,updaterId:HPCDKMSV763K2VGHCKQQ09QSGM]
答案 0 :(得分:1)
修改强>
当您记录“已更新的内容”时,它将其识别为Map对象并打印其字段。您需要使用可以将Map对象转换为JSON并将其打印出来的东西。有很多方法可以做到这一点,例如:
def json = JsonOutput.toJson(updatedjson)
println json