3

您好我正在尝试从我的一个 REST 端点序列化一组 CFC。我在 Adob​​e 帮助中找到了这个示例:CFC 序列化数组 ,这几乎正是我想要做的(如果需要,我可以发布一些代码)但是当我尝试使用returnType="myCFC[]"它时失败了:

"Message":"数组元素类型不匹配"

奇怪的是,如果我实例化同一个对象并从 .cfm 文件调用该方法,cfdump 会按预期显示包含数据的对象数组。但是从我的 AJAX 调用中,对象的属性值都是空的。但是,如果我使用 returnserializeJSON(myArrayOfCFCs)属性有数据。但我不想这样做,因为它会否定内容协商的使用。

只是好奇是否有人让这个工作。

更新:

 <cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient[]" produces="text/json" restpath="/{PatientId}">
    <cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />

    <cfset local.response = ArrayNew(1) />
    <cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>

    <cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
    <cfset arrayAppend(local.response, local.patientObject) />

    <cfreturn local.response />

 </cffunction>

这有效,但最终不是我想要的:

 <cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient" produces="text/json" restpath="/{PatientId}">
    <cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />

    <cfset local.response = ArrayNew(1) />
    <cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>

    <cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
    <cfset arrayAppend(local.response, local.patientObject) />

    <cfreturn serializeJSON(local.response) />

 </cffunction>
4

0 回答 0