Coldfusion 8 - SerializeJSON没有序列化

时间:2011-11-09 22:29:57

标签: json coldfusion coldfusion-8 cfc

我一直在WAMP设置上离线开发一个站点,并且一直使用SerializeJSON函数序列化bean,如下所示:

propertyImageBean = CreateObject("component","cfcs.beans.property_image").init();
propertyImageBean.setname("test");
propertyImageBean.setalt("test alt");

<cfoutput>#SerializeJSON(propertyImageBean)#</cfoutput>

这一切都正常工作,上面的代码产生:

{"name":"test","alt":"asdasd","id":""}

但是,当我将文件上传到实际网站时,响应只是一个空对象:

{}

本地版本在CF9上运行,prod版本在CF8上运行,所以这可能是问题所在。

有什么想法吗?

由于

编辑:

<cfscript>

    propertyImageBean = CreateObject("component","cfcs.beans.property_image").init();
    propertyImageBean.setid(1);
    propertyImageBean.setname("test");
    propertyImageBean.setalt("asdasd");

</cfscript>
<cfdump var=#propertyImageBean#>
<cfoutput>id: #propertyImageBean.getid()#</cfoutput>
<cfoutput>alt: #propertyImageBean.getalt()#</cfoutput>
<cfoutput>name: #propertyImageBean.getname()#</cfoutput>

输出(prod服务器(:

  • bean的转储但不在转储中显示bean属性,而在本地服务器上则显示

    id:1 alt:asdasd name:test

所以看起来这是bean的问题,除非服务器上有配置问题。

CFC:

<!--- PROPERTIES FOR DOCUMENTATION PURPOSES ONLY --->
<cfproperty name="id" displayname="id" hint="id of the property_image" type="any" required="True" />
<cfproperty name="name" displayname="name" hint="name of the property_image" type="any" required="True" />
<cfproperty name="alt" displayname="alt" hint="alt of the property_image" type="any" required="True" />

<!--- PSEUDO-CONSTRUCTOR: SETS DEFAULT VALUES IF INIT METHOD IS NOT CALLED --->
<cfscript>
    variables.id = "";
    variables.name = "";
    variables.alt = "";
</cfscript>

<!--- CONSTRUCTOR: TAKES IN ARGUMENTS AND CALLS SETTER (MUTATOR) FOR EACH ATTRIBUTE OF THE BEAN --->
<cffunction name="init" displayname="Init" hint="Constructor for the CFC" access="public" output="false" returntype="any">
    <!--- ARGUMENTS FOR THE CONSTRUCTOR, ALL OF WHICH ARE OPTIONAL (NO-ARG CONSTRUCTOR) --->
    <cfargument name="aid" displayname="id" hint="id of the property_image" type="any" required="false" default="" />
    <cfargument name="aname" displayname="name" hint="name of the property_image" type="any" required="false" default="" />
    <cfargument name="aalt" displayname="alt" hint="alt of the property_image" type="any" required="false" default="" />
    <!--- CALL THE SETTERS (MUTATORS) FOR EACH OF THE property_image ATTRIBUTES AND PASS IN THE ARGUMENTS --->
    <cfscript>
        setid(arguments.aid);
        setname(arguments.aname);
        setalt(arguments.aalt);
    </cfscript>

    <cfreturn this />
</cffunction>

<!--- GETTERS AND SETTERS (MUTATORS AND ACCESSORS) --->
<cffunction name="getid" access="public" output="false" returntype="string">
    <cfreturn variables.id />
</cffunction>
<cffunction name="setid" access="public" output="false" returntype="void">
    <cfargument name="aid" type="string" required="true" />
    <cfset variables.id = arguments.aid />
</cffunction>
<cffunction name="getname" access="public" output="false" returntype="string">
    <cfreturn variables.name />
</cffunction>
<cffunction name="setname" access="public" output="false" returntype="void">
    <cfargument name="aname" type="string" required="true" />
    <cfset variables.name = arguments.aname />
</cffunction>
<cffunction name="getalt" access="public" output="false" returntype="string">
    <cfreturn variables.alt />
</cffunction>
<cffunction name="setalt" access="public" output="false" returntype="void">
    <cfargument name="aalt" type="string" required="true" />
    <cfset variables.alt = arguments.aalt />
</cffunction>

2 个答案:

答案 0 :(得分:1)

我要查看serializeJson()或CFC的方法是否有问题。检查以确保值实际上已设置:getName()和getAlt()是否返回您期望的值?

是否有可能在生产环境中出现同时请求意外重新启动该CFC实例的问题?

你能做一个完全独立的CFM&amp; CFC都削减到绝对最小数量的“活动部件”以证明这个问题,并且仍然在dev&amp; amp;督促?

答案 1 :(得分:1)

首先,在本地设置CF8。 http://www.adobe.com/support/coldfusion/downloads.html#cf8proddl

我认为SerializeJSON(cfc)是CF9中的新功能,在CF8中不可用。这不是SerializeJSON我不相信的官方记录特征。

实现一个getMemento()函数,该函数以结构形式返回变量,然后在该结构上可以使用SerializeJSON。

/** a public function in Obj.CFC */
function getMemento()
{
    return {
        x=variables.x,
        y=variables.y
    };
}

// outside of the cfc...
obj = createComponent("component","Obj").init();
objJson = serializeJSON(obj.getMemento());