0

Need to iterate WorkorderID .......values ....and these are List Objects which has List of Map and values is an array []

"answers": [
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.CustomerName",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "CustomerName"
        ]
      },
      "label": "CustomerName",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Customer Name",
      "values": [
        "GALWAY CLINIC"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.CustomerAddress",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "CustomerAddress"
        ]
      },
      "label": "CustomerAddress",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Customer Address",
      "values": [
        "Doughiska"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.CustomerCity",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "CustomerCity"
        ]
      },
      "label": "CustomerCity",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Customer City (Location)",
      "values": [
        "Galway"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.Country",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "Country"
        ]
      },
      "label": "Country",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Country",
      "values": [
        "Ireland"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.WorkOrderNumber",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "WorkOrderNumber"
        ]
      },
      "label": "WorkOrderNumber",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Work Order Number",
      "values": [
        "WO-00293752"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.StartDate",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "StartDate"
        ]
      },
      "label": "StartDate",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Start Date",
      "values": [
        "2018-12-12 21:45:00"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.InstalledProductID",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "InstalledProductID"
        ]
      },
      "label": "InstalledProductID",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Installed Product ID",
      "values": [
        "42613320"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.SerialNumber",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "SerialNumber"
        ]
      },
      "label": "SerialNumber",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "Serial Number",
      "values": [
        "712050PF"
      ]
    },
    {
      "labelFullPath": {
        "path": "WorkOrderInformation.WorkOrderInfoFlow.WorkOrderID",
        "components": [
          "WorkOrderInformation",
          "WorkOrderInfoFlow",
          "WorkOrderID"
        ]
      },
      "label": "WorkOrderID",
      "dataType": "FreeText",
      "controlType": "SmallTextbox",
      "question": "WorkOrderID",
      "values": [
        "a3d290000007L5Q"
      ]
    },
1
  • Need to fetch WorkOrderID ... Values which is "a3d290000007L5Q" in this case
    – user62829
    Dec 13 '18 at 7:08
0

You can create an Object with members named as fields of json:

public class YourObject {
   CustomLabelPathObject labelFullPath//create similar object if you need to parse it.
   String label;
   String question;
   List<String> values;
}

Then deserialize it:

 List<YourObject> yourObjects  =(List<YourObject>)JSON.deserialize(jsonString, List<YourObject>.class);

and then iterate yourObjects list to fetch values:

for (YourObject curr :yourObjects) {
   if ("WorkOrderID".equals(curr.question) {
      // fetch or assign curr.values
 }
0

Firstly you can use Map to deserialize the JSONas shown below-

Map<String,Object> mapDesVal = (Map<String,Object>)JSON.deserializeUntyped(jsonInput);

Then you can do something like this - 
Map<String,Object> mapVal = (Map<String,Object>)mapDesVal.get('answers');

if(mapVal.get('question') == 'WorkOrderID'){
    mapVal.get('values');
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.