EDIT:
Object result = JSON.deserializeUntyped(payload);
if (result instanceof Map<String, Object>) {
Map<String, Object> resultMap = (Map<String, Object>)result;
system.debug('result: ' + resultMap.get('records')); //returns null
}
//END EDIT
How to loop through the nested json key/value for an example how can I get the values for this attributes Records==>attributes==>url
or Metadata=>formula
APEX Code:
String payload = '.... json...'
Map<String, Object> jsonMap = (Map<String, Object>)JSON.deserializeUntyped(payload);
List<Object> records = (List<Object>) jsonMap.get('records'); //get the records
if (records != null) {
for (Object r : records) {
//for (string r2 : r.get('url')) { //error incorrect signature
system.debug(r.value);
//}
}
} else {
system.debug('null.. : ' + records);
}
JSON
{
"size": 1,
"totalSize": 1,
"done": true,
"queryLocator": null,
"entityTypeName": "CustomField",
"records": [
{
"attributes": {
"type": "CustomField",
"url": "/services/data/v46.0/tooling/sobjects/CustomField/00N6g00000TAlZNEA1"
},
"Metadata": {
"businessOwnerGroup": null,
"businessOwnerUser": null,
"formula": "IMAGE( \nCASE(Rating__c, \n\"Very Bad\", \"/img/samples/stars_100.gif\",\n\"Bad\", \"/img/samples/stars_200.gif\",\n\"Okay\", \"/img/samples/stars_300.gif\", \n\"Good\", \"/img/samples/stars_400.gif\", \n\"Very Good\", \"/img/samples/stars_500.gif\", \n\"/img/samples/stars_000.gif\"), \n\"rating\")",
"formulaTreatBlanksAs": "BlankAsZero"
}
}
]
}
null
values when I try to extract the key/value, please take a look. – Nick Kahn Jun 9 '20 at 22:33