执行cfc时出错:函数返回的值不是json类型

时间:2017-07-19 16:56:49

标签: coldfusion cfc

我在ColdFusion中编写了一个Web服务,它通过检查数据库中的输入值来返回消息(成功/失败)。 要运行cfc,我直接在URL中提供参数,如下所示: 的 http://localhost/AimsWeb/Authenticate2.cfc?method=AuthenticateUser&returnformat=json&CustomerID=1&username=xxx&password=xxxx 但是当我运行此页面时,它会以如下错误结束: enter image description here

这是我的CFC:

<cfcomponent rest="true" restpath="/AimsWeb"> <!--- REST Service--->

<cffunction name="AuthenticateUser" access="remote" httpmethod="POST"  returnFormat="JSON" returntype="json">

<!---- Defining Arguments--->
    <cfargument name="Username" type="string" required="Yes">
    <cfargument name="Password" type="string" required="Yes">
    <cfargument name="CustomerID" type="string" required="Yes">

<!---- Setting the Form Values (which we will get from AW+) and setting it to arguments passed--->
    <cfset Form.CustomerID = arguments.CustomerID>
    <cfset Form.Username = arguments.Username>
    <cfset Form.Password = Hash(arguments.Password)>

<cfif StructKeyExists (form, 'CustomerID') and StructKeyExists(form, 'UserName') and StructKeyExists (form, 'password')>
   <cfquery name="AllUsers" datasource="#Application.GomDatasource#">
    SELECT u.UserTypeID, u.UserID, u.CustomerID, u.UserName, u.Password
     FROM tblUsers u
    WHERE u.CustomerID = <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.CustomerID#">
   </cfquery>



<!--- This is to check whether provided parameters are valid by checking the same in the database--->
<cfset local.StatusStruct = StructNew()>

<cfif form.customerid EQ "" OR form.username EQ "" OR form.password EQ "">
    <cfset local.StatusStruct['errorCode'] = 400>
    <cfset local.StatusStruct['errorMessage'] = "Insufficient Input.">

<cfelseif AllUsers.RecordCount AND form.CustomerId EQ AllUsers.CustomerID AND form.username EQ AllUsers.UserName AND form.password EQ AllUsers.Password>
    <cfset local.StatusStruct['errorCode'] = 200>
    <cfset local.StatusStruct['errorMessage'] = "Success">

<cfelseif AllUsers.CustomerID NEQ form.CustomerID>
    <cfset local.StatusStruct['errorCode'] = 400>
    <cfset local.StatusStruct['errorMessage'] = "Customer Id doesn't exist">

 <cfelseif AllUsers.UserName NEQ form.UserName>
    <cfset local.StatusStruct['errorCode'] = 400>
    <cfset local.StatusStruct['errorMessage'] = "User not found">

 <cfelseif AllUsers.Password NEQ form.password>
    <cfset local.StatusStruct['errorCode'] = 400>
    <cfset local.StatusStruct['errorMessage'] = "Invalid Password">
</cfif>

    <!--- Returning the status in JSON form--->

</cfif>
<cfreturn local.StatusStruct>
  </cffunction>

</cfcomponent>

有人可以帮我吗?

1 个答案:

答案 0 :(得分:2)

它奏效了。 returntype=json无效。我删除了那条线并且它有效。

<cffunction name="AuthenticateUser" access="remote" httpmethod="GET"  returnFormat="JSON">

感谢大家的帮助。