0

I am getting the below Json Response by hitting a RestAPI.

**

[
    {
        "index": 0,
        "object": {
            "attributes": {
                "ID": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/ID",
                        "ov": true,
                        "value": "5",
                        "uri": "entities/attributes/ID/2Cqf5xG2"
                    },
                    {
                        "type": "configuration/entityTypes/Customer/attributes/ID",
                        "ov": true,
                        "value": "3028",
                        "uri": "entities/attributes/ID/fto38ZRR"
                    }
                ],
                "IgpId": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpId",
                        "ov": true,
                        "value": "1911",
                        "uri": "entities/attributes/IgpId/20ft8omYM"
                    }
                ],
                "IgpName": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpName",
                        "ov": true,
                        "value": "Dr. heath",
                        "uri": "entities/attributes/IgpName/20ft8oe1q"
                    }
                ],
                "IgpID": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpID",
                        "ov": true,
                        "value": "1872",
                        "uri": "entities/attributes/IgpID/20ft8oiI6"
                    }
                ],
                "IgpNAME": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpNAME",
                        "ov": true,
                        "value": "Dr Jc crook",
                        "uri": "entities/attributes/IgpNAME/20ft8oqoc"
                    }
                ]
            }
        },
        "successful": true
    }
]

**

I am trying to save the values for CoachID (3028), IgpID(1872), IgpId(1911), IgpName(Dr. heath), IgpNAME(Dr Jc crook) in String variables in APex class.

I have used a map to do so but unable to get the proper values. I wanted to get the above values in a List & return that list from function.

Can anyone help me on this? I am not supposed to do this using wrapper.

Regards, Mohit

Mohit Mathuriya
  • 25
  • 2
  • 10

1 Answers1

0

It can't be done as straight "JSON.deserialize" call because some fields are reserved keywords in Apex. How strict the wrapper ban is? I wouldn't want to type this stuff freehand but you can go to https://json2apex.herokuapp.com/, tick checkbox about explicit parser (again, since you have reserved keywords it'd happen anyway) and well, you have a ready class & cool stab at unit test / example how to use the code. It's battle-tested, if you can't use that then your project has bigger problems ;)

If you really really have to do it alone and with maps it'll be something like https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm, example for deserializeUntyped

eyescream
  • 18,088
  • 2
  • 34
  • 46