如何在SOAP UI中的JSON Response中将NULL字段置为NULL

时间:2013-02-21 07:41:28

标签: soapui

如何在SOAP UI的JSON响应中将NULL字段置为

示例:如果使用Soap UI中的Assert选项,如果Children为null,我需要断言数据。

  {
  "request":    {
  "parameters": {"SOURCE_NAME":       {
     "name": "Members_Sheet1",
     "caseSensitivity": "CASE_SENSITIVE",
     "inputMatchingOperator": "EXACT"
  }},
  "metadata": {}
                },
        "data":    {
  "results": [{"data": {"Members_Sheet1":       [
              {
        "Sl No": 1,
        "Member ID": 70000001,
        "Member Name": "Fly Dorami",
        "Location": "New York",
        "DOB": "4/12/2008",
        "Gender": "M",
        "Marital Status": "Single",
        "Children": "",
        "Ethnicity": "Asian",
        "Insurance Plan ID": 2002,
        "Annual Income ($)": 0,
        "Twitter User ID": 548900028

1 个答案:

答案 0 :(得分:5)

你引用的JSON在Children中有空字符串,它不是NULL。为此,您可能需要使用启用ResponseAsXML属性将JSON转换为XML。

替代方法是使用 groovy脚本断言;

import groovy.json.JsonSlurper 
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText response

// json variable has all your data
assert // statement