I am running into an issue getting values from my json payload.
The schema is as follows:
{
"thank_you_message": "Спасибо, что нашли время на прохождение нашего опроса. Ваше мнение очень важно для нас.",
"Survey_Choices__c": [
{
"attributes": {
"type": "ВыборВопросаОпроса",
"url": "/services/data/v49.0/sobjects/SurveyQuestionChoice/0Kct0000000KzFyCAK"
},
"Name": "Интернет",
"SurveyVersionId": "0Kst0000000KyjzCAC",
"DeveloperName": "c_0dc4ff3e_13c5_46dd_b3e7_b5e9d2af8679",
"Id": "0Kct0000000KzFyCAK"
},
{
"attributes": {
"type": "ВыборВопросаОпроса",
"url": "/services/data/v49.0/sobjects/SurveyQuestionChoice/0Kct0000000KzFzCAK"
},
"Name": "мыПереводим",
"SurveyVersionId": "0Kst0000000KyjzCAC",
"DeveloperName": "c_296e4586_c4c3_43aa_8b55_4bb2f643befd",
"Id": "0Kct0000000KzFzCAK"
}]
}
I need to loop through all Survey_Choices__c
but am running into problems.
My attempted steps
- Deserialize the json payload:
Map<String, Object> surveyMap = (Map<String, Object>) JSON.deserializeUntyped(output);
Get the survey choice objects (I wanted to set this up as a
Map<String,Object>
, but I get a conversion error must beList<Object>
)Use the following code to loop through each key-value pair
List<Object> surveyChoices = (List<Object>) surveyMap.get('Survey_Choices__c');
Map<String, Object> test = new Map<String, Object>();
for (Object s : surveyChoices) {
test.putAll((Map<String, Object>) s);
}
System.debug(test);
The above code only prints out one json object in the array.
My question is how can I loop through the array of JSON objects and get the name value of each object.
]
. Was that intentional?]
Map<String,Object> surveyChoices = (Map<String,Object>) surveyMap.get('Survey_Choices__c');
Survey_Choices__c
is not an object, but a list of objects