Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要使用Groovy打印JSON响应中每个节点的值_Json_Groovy_Soapui - Fatal编程技术网

需要使用Groovy打印JSON响应中每个节点的值

需要使用Groovy打印JSON响应中每个节点的值,json,groovy,soapui,Json,Groovy,Soapui,我有一个来自web服务的JSON响应,如下所示: { "status": true, "statusCode": "OK", "requestId": "b9c0ffe3-2b62-465d-bc0f-48a1279c3a54", "responseData": {"ResDoc": { "resume": { "@canonversion": "2", "@dateversion": "2",

我有一个来自web服务的JSON响应,如下所示:

{
   "status": true,
   "statusCode": "OK",
   "requestId": "b9c0ffe3-2b62-465d-bc0f-48a1279c3a54",
   "responseData": {"ResDoc":    {
      "resume":       {
         "@canonversion": "2",
         "@dateversion": "2",
         "@iso8601": "2015-10-16",
         "@present": "735889",
         "@xml:space": "preserve",
         "#text": "\t\t\tCURRICULUM VITAE\n",
         "contact":          {
            "name":             {
               "givenname": "Mark",
               "surname": "Brittain"
            },
            "#text":             [
               "\nFlat 2\n",
               " 181 410\n\t\t\t\t\t\t\t\t  "
            ],
            "address":             {
               "@lat": "40.7031",
               "@lon": "74.6402",
               "@majorcity": "EDISON",
               "@state": "NJ",
               "street": "20 tmp street",
               "#text": "\nYork\nY01 6EE\n01904675328\n\t\t\t\t\t\t\t\t\t\t",
               "postalcode": "21014"
            },
            "email": "sdf33r@aol.com"
         },
         "summary":          {
            "#text":             [
               "INTRODUCTION\n\n",
               "  \n\nKEY SKILLS\n\n"
            ],
            "objective": "Since my graduation from Manchester Metropolitan University in June 2000 I have maintained a career in financial administration and wish to remain in an administrative/clerical role. The skills I have established during my educational and professional career are well suited to an administrative position within a proactive and inspiring environment, where they can be met to their full potential.",
            "summary": "Excellent inter-personal skills with the ability to effectively communicate with team members, clients, and company departments.\n\nEffective eye for detail and rapid problem solving skills with the ability to prioritise and check work.\n\nThe ability to work with initiative and enthusiasm to learn new skills when \trequired.\n\nHighly PC literate with an ability to use Microsoft Excel effectively when \tformatting spreadsheets for the simplification and reconciliation of numerical \tdata.  Knowledge in the use of formulas when setting up accounting data / numerical records. The ability to use access databases effectively.\n\nPunctual, reliable and organised with an ability to produce neat and tidy work.  Hard working with and highly driven an ambition to succeed.\n\nExcellent business performance, time management and client management skills.\n\nThe ability to be a team player if required due to an outgoing personality and friendly nature."
         },
         "education":          {
            "#text":             [
               "EDUCATION\n\n",
               ". I have a ",
               " in ",
               " with Leisure (",
               ")"
            ],
            "daterange":             [
                              {
                  "start":                   {
                     "@days": "727200",
                     "@iso8601": "1992-01-01",
                     "#text": "1992"
                  },
                  "#text": "-",
                  "end":                   {
                     "@days": "727200",
                     "@iso8601": "1992-01-01",
                     "#text": "1992"
                  }
               },
                              {
                  "start":                   {
                     "@days": "727566",
                     "@iso8601": "1993-01-01",
                     "#text": "1993"
                  },
                  "#text": "-",
                  "end":                   {
                     "@days": "728661",
                     "@iso8601": "1996-01-01",
                     "#text": "1996"
                  }
               },
                              {
                  "start":                   {
                     "@days": "728661",
                     "@iso8601": "1996-01-01",
                     "#text": "1996"
                  },
                  "#text": "-",
                  "end":                   {
                     "@days": "729757",
                     "@iso8601": "1999-01-01",
                     "#text": "1999"
                  }
               }
            ],
            "description":             [
               "During this period of time I obtained 8 GCSE's all above grade C. \tThese \tinclude Maths and English.",
               "I gained three A' levels all at grade C. These included Business, \tFinance, and Economics."
            ],
            "degree":             {
               "@level": "16",
               "@name": "Bachelor of Arts",
               "#text": "BA Honours Degree"
            },
            "major":             {
               "@code": "4399",
               "#text": "Business Studies"
            },
            "gpa": "2.2"
         },
         "experience":          {
            "@end": "present",
            "@start": "727566",
            "#text": "EMPLOYMENT HISTORY\n\n",
            "job":             [
                              {
                  "@end": "728661",
                  "@id": "1",
                  "@pos": "8",
                  "@span": "3",
                  "@start": "727566",
                  "description":                   [
                     "Summer holidays during education",
                     "Work experience gained working at my father�s solicitors office chambers based in Liverpool employed as a Clerical Assistant undertaking administrative roles including filing, faxing, and word processing.  I became familiar in  the use of spreadsheets and databases for the classification of records and organisation of numerical data.\n\n\nSummer holidays during university"
                  ],
                  "daterange":                   {
                     "start":                      {
                        "@days": "727566",
                        "@iso8601": "1993-01-01",
                        "#text": "1993"
                     },
                     "#text": "- ",
                     "end":                      {
                        "@days": "728661",
                        "@iso8601": "1996-01-01",
                        "#text": "1996"
                     }
                  },
                  "#text": "\n (August to September) \t\t\t\t",
                  "title": "Clerical Assistant"
               },
                              {
                  "@end": "729027",
                  "@id": "2",
                  "@pos": "7",
                  "@span": "0",
                  "@start": "729027",
                  "daterange":                   [
                                          {
                        "start":                         {
                           "@days": "729027",
                           "@iso8601": "1997-01-01",
                           "#text": "1997"
                        },
                        "#text": "-",
                        "end":                         {
                           "@days": "729027",
                           "@iso8601": "1997-01-01",
                           "#text": "1997"
                        }
                     },
                                          {
                        "start": "May",
                        "#text": " to ",
                        "end": "September"
                     }
                  ],
                  "#text":                   [
                     " (",
                     ") \t\t\t\t"
                  ],
                  "title": "Bar Supervisor",
                  "description": "Employed by Bass Taverns working as bar supervisor in public house based in my hometown.  The job required a high level of responsibility as I mainly worked nights.  I could be working on my own a lot which helped me develop a strong sense of responsibility and initiative. I always took pride in my position and ensured I did a good job.  The bar was always kept clean and tidy. It was also my responsibility to ensure stock taking was up to date. \n\n\tSummer holidays during university"
               },
                              {
                  "@end": "729392",
                  "@id": "3",
                  "@pos": "6",
                  "@span": "0",
                  "@start": "729392",
                  "daterange":                   [
                                          {
                        "start":                         {
                           "@days": "729392",
                           "@iso8601": "1998-01-01",
                           "#text": "1998"
                        },
                        "#text": "-",
                        "end":                         {
                           "@days": "729392",
                           "@iso8601": "1998-01-01",
                           "#text": "1998"
                        }
                     },
                                          {
                        "start": "May",
                        "#text": " to ",
                        "end": "September"
                     }
                  ],
                  "#text":                   [
                     " (",
                     ")\t\t\t\t"
                  ],
                  "title": "Clerical Assistant",
                  "description": "Temporary employment through �Kelly recruitment Services�, working for British Telecom based in Chester.  Job specification included maintaining an effective and up to date database of customers paying their phone bills by direct debit. The job involved searching databases, printing letters and various correspondence with customers. The job developed certain skills of mine such as checking for accuracy, corresponding with customers, handling customer complaints, and inputting numerical data. \n\n\tSummer holidays during university"
               },
                              {
                  "@end": "729757",
                  "@id": "4",
                  "@pos": "5",
                  "@span": "0",
                  "@start": "729757",
                  "daterange":                   {
                     "start":                      {
                        "@days": "729757",
                        "@iso8601": "1999-01-01",
                        "#text": "1999"
                     },
                     "#text": "-",
                     "end":                      {
                        "@days": "729757",
                        "@iso8601": "1999-01-01",
                        "#text": "1999"
                     }
                  },
                  "#text": " (",
                  "description": "June to September) \t\t\tTelesales Agent\n\nTemporary employment through �Addecco Recruitment�, working for �Richard Hogg Linley Ltd� based in Liverpool.  The job was 'telesales' related and included the formatting of  access databases for senior sales advisors to contact potential customers (newsagent owners) to whom they could sell cheap insurance. The job was mainly to establish the insurance renewal dates of these customers and other important details. This developed stronger communication skills of mine when dealing with customers.  I ensured my databases were always accurate and effective, making the job for senior sales advisors very easy and straightforward."
               },
                              {
                  "@end": "730091",
                  "@id": "5",
                  "@pos": "4",
                  "@span": "0",
                  "@start": "730000",
                  "daterange":                   {
                     "start":                      {
                        "@days": "730000",
                        "@iso8601": "1999-09-01",
                        "#text": "September 1999"
                     },
                     "#text": " - ",
                     "end":                      {
                        "@days": "730091",
                        "@iso8601": "1999-12-01",
                        "#text": "December 1999"
                     }
                  },
                  "description": "Returned to university to complete dissertation.  My final term was dedicated to a dissertation research project .  Please note I finished my degree in December 1999 but graduation was not until June 2000."
               },
                              {
                  "@id": "6",
                  "daterange":                   {
                     "start": "February 18",
                     "#text": " - ",
                     "end": "30 April 2000"
                  },
                  "#text": ".\t\t\t\t",
                  "title": "Clerical / Admin Assistant",
                  "description": "Temporary employment through 'Forest Recruitment' working for 'Premium Pet Care Ltd' based in Liverpool.  The job specification included dealing with customers� returned orders either because they were faulty or the wrong goods had been dispatched from the companies warehouse.  The job involved excellent communication skills as it involved corresponding on a regular basis with dissatisfied customers and the companies warehouse operatives. The job also required updating customer records and payment history through an access database."
               },
                              {
                  "@end": "730335",
                  "@id": "7",
                  "@pos": "3",
                  "@span": "0",
                  "@start": "730243",
                  "employer": "01",
                  "daterange":                   {
                     "start":                      {
                        "@days": "730243",
                        "@iso8601": "2000-05-01",
                        "#text": "May 2000"
                     },
                     "#text": " - ",
                     "end":                      {
                        "@days": "730335",
                        "@iso8601": "2000-08-01",
                        "#text": "15 August 2001"
                     }
                  },
                  "title": "Pensions Administrator",
                  "description": "Permanent employment with pension specialists 'HS Administrative Services Ltd' (now part of AGON Ltd).  The Job specification as a �Pensions Administrator� included meeting the day-to-day administration needs of a portfolio of clients in an accurate and timely manner.  The job involved dealing with �final salary� pension schemes by providing clients and their employees with any details regarding their occupational pension benefits. This included submitting information to current active employees who had benefits within the pension scheme, preserved members within the company's pension scheme, and retired members to whom we were paying  retirement benefits.\n\nIt involved calculating current employee pension benefits and projecting their value at retirement date whilst also ensuring the reliability and accuracy of their pension records.  Communication was a key aspect of the job as it required much correspondence with my various clients, the Inland Revenue and Independent Financial Advisors to ensure that target dates and deadlines were met. Key skills such as organisation and an effective eye for detail were very important in the job.  Numerical accuracy was imperative."
               },
                              {
                  "@end": "730761",
                  "@id": "8",
                  "@pos": "2",
                  "@sic": "541100",
                  "@sic2": "54",
                  "@span": "0",
                  "@start": "730700",
                  "employer":                   [
                     "28",
                     "Jardine Lloyd Thompson Benefit Solutions Ltd"
                  ],
                  "daterange":                   {
                     "start":                      {
                        "@days": "730700",
                        "@iso8601": "2001-08-01",
                        "#text": "August 2001"
                     },
                     "#text": " - ",
                     "end":                      {
                        "@days": "730761",
                        "@iso8601": "2001-10-01",
                        "#text": "15 October 2003"
                     }
                  },
                  "title": "Pensions Administrator",
                  "#text":                   [
                     "\n\nPermanent employment with '",
                     "'.  "
                  ],
                  "description": "The job specification as a �Pensions Administrator� was very similar but required a great deal more of responsibility including an accurate financial review over the pension scheme bank accounts.  Key skills including the effective review of numerical data and problem solving skills were imperative for daily tasks to be carried out effectively.  \n\nMy clients were mainly companies with 'Money Purchase' occupational pension schemes where pension contributions are invested monthly however employee�s benefits are dependent on market annuities and unit prices. The job required constant liaisons with clients and investment managers to ensure contributions are paid on time. A confident attitude was essential for the sole responsibility of client�s accounts and their reconciliation as was and the monitoring of daily transactions and account balances of the pension scheme accounts. I proved I could work to strict deadlines, maintain excellent relationships with clients and work under pressure."
               },
                              {
                  "@end": "present",
                  "@id": "9",
                  "@pos": "1",
                  "@sic": "999977",
                  "@sic2": "99",
                  "@span": "11",
                  "@start": "731857",
                  "employer": "31",
                  "daterange":                   {
                     "start":                      {
                        "@days": "731857",
                        "@iso8601": "2004-10-01",
                        "#text": "October 2004"
                     },
                     "#text": " - ",
                     "end":                      {
                        "@days": "present",
                        "@iso8601": "2015-10-16",
                        "#text": "Presently"
                     }
                  },
                  "title": "Pensions Administrator",
                  "description": "Permanent employment with �Pensions & Benefits Services Ltd.�  The job specification is strictly related to a final salary pension scheme and is to effectively participate in the administration of our one and only client.  This includes calculating pension benefits and corresponding with members of the pension scheme, active and preserved members.  It is also to arrange and process the transfer of pension benefits to other existing pension arrangements.  This process requires excellent time management skills, for example, the ability to diary and chase up correspondence.  A close eye on target /guarantee dates is also important.  The job requires excellent organisational skills and the ability to use self initiative as well as working as part of a team."
               }
            ]
         },
         "references": "References will be provided on request"
      }
   }},
   "processedWithLocale": "en_us",
   "timeStamp": "2015-10-16 17:57:58.330"
}
我试图在SOAPUI中编写一个Groovy脚本,以逐个打印所有子节点和子节点的子节点的值(或上述JSON响应中所有键的值)

我使用下面的Groovy脚本来实现这一点:

import groovy.json.JsonSlurper

responseContent = testRunner.testCase.getTestStepByName("ParseResume_ValidText_ReturnSuccess").getPropertyValue("response")
slurperresponse = new JsonSlurper().parseText(responseContent)

def parseMap(map){
 map.each{ 
  try{
   if(it!=null){
    //log.info(it.key)
   }
   if(it.value.getClass() == slurperresponse.getClass()){
    parseMap(it.value)}
   else{
    log.info(it.key + ": " + it.value)
   }

  }
  catch(Exception ex){
   log.info(ex.getMessage())
  }
 }
}

parseMap(slurperresponse)
它将打印所有子节点值,但数组中的值(例如教育节点值下的daterange部分)不会逐个显示。它只是作为一个团体写的


请在这方面帮助我。

可能会添加另一个函数来循环遍历数组,例如循环遍历映射的
parseMap
函数:

def parseMap(map){
   map.each{
       if(it.value instanceof Map){
           parseMap(it.value)
       }else if(it.value instanceof List){
           log.info(it.key + ": ")
           parseArray(it.value)
       }else{
           log.info(it.key + ": " + it.value)
       }
    }
}

def parseArray(array){
     array.each{ 
         if(it instanceof Map){
              parseMap(it)
         }else if(it instanceof List){
              parseArray(it)
         }else{
              log.info("arrayValue: $it");
         }
     }
}

parseMap(slurperresponse)
希望这有帮助,

或其他选择:

import groovy.json.*

class Dumper {
    String name
    void dump(obj) {
        println "$name -> '''$obj'''"
    }
    void dump(List list) {
        list.each {
            dump(it)
        }
    }
    void dump(Map map) {
        map.each { key, value ->
            switch(value) {
                case List:
                    name = key
                case Map:
                    dump(value)
                    break;
                default:
                    println "$key -> '''$value'''"
            }
        }
    }
}

new Dumper().dump(new JsonSlurper().parseText(json))