Map string arraylist getting key and value

Prabu :

From the API response, I'm parsing the JSON

String myData = jsonSlurper.parseText(responseBody)
Map parsedBiblio = jsonSlurper.parseText(myData)

below is the output of parsedBiblio

{"Data": {"AppNumber": "15671037", "CustomerNumber": "81744", "Date": "08-07-2017", "Status": "Active"}, 

 "Applicants": [{"Name": "abcd Inc.", "Address": "xxx, CA (US)"}],

below is the code of reterieving the Data key and corresponding value

Map<Object, Object> innerMap = parsedBiblio.get("Data")
for (Object objectName : innerMap.keySet()) {

       println("Key: " + objectName + " Value: "+ innerMap.get(objectName) +".");
 }

Let me know how can i reterieve the Applicants Key,and the corresponding values, because this is map<string,List<string> format, so i will declare the innermap in the below format

Map<String, List<String>> innerMapApplicant = parsedBiblio.get("Applicants")

I'm getting the below error

 Cannot cast object '[{Address=xxx, CA (US), Name=abcd Inc.}]' with class 'java.util.ArrayList' to class 'java.util.Map' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.Map(groovy.json.internal.LazyMap)
Tarun :

I think you should try retrieving Applicant as follow:

List<Map<String,String>> applicantList =  = parsedBiblio.get("Applicants")

You can fetch key and value in the map as follow :

  for(Map<String,String> applicantMap: applicantList)
  {
       for (Object objectName : applicantMap.keySet()) 
       {
          println("Key: " + objectName + " Value: "+ applicantMap.get(objectName) +".");
       }
   }

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=396578&siteId=1