JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeFieldName('Patient Satisfactions');
gen.writeStartArray();
for (Patient_Satisfaction__c patientSatisfaction : patientSatisfactions) {
gen.writeStartObject();
gen.writeStringField('First name', patientSatisfaction.Reporter_First_Name__c);
gen.writeStringField('Last name', patientSatisfaction.Reporter_Last_Name__c);
gen.writeStringField('Phone', patientSatisfaction.Reporter_Phone__c);
gen.writeStringField('description', patientSatisfaction.Description_of_Feedback__c);
gen.writeStringField('Name', patientSatisfaction.Name);
gen.writeNumberField('incident_group_id', 7387);
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeEndObject();
String jsonData = gen.getAsString();
restContext.response.responseBody= blob.valueOf(jsonData);
system.debug('Json data'+jsonData );
No comments:
Post a Comment