Json 替换CFC中的数据

Json 替换CFC中的数据,json,coldfusion,coldfusion-9,Json,Coldfusion,Coldfusion 9,我有一个简单的CFC页面,它以JSON格式输出数据: <cffunction name="test" access="remote" returnformat="plain" output="true"> <cfquery datasource="#dns#" name="rs.q" maxrows="5"> select text from table </cfquery> <cfreturn serializeJSON( r

我有一个简单的CFC页面,它以JSON格式输出数据:

<cffunction name="test" access="remote" returnformat="plain" output="true">
<cfquery datasource="#dns#" name="rs.q" maxrows="5">
select      text
from        table
</cfquery>

<cfreturn serializeJSON( rs.q ) /> 
</cffunction>

选择文本
从桌子上
查询输出的文本可以包含图像,例如,
/webimages/1.jpg
。现在,对于Web服务,我想搜索图像并将其替换为
http://domain.com/webimages/1.jpg

这可以在CFC文件中完成吗?


<cffunction name="test" access="remote" returnformat="json" output="false">
  <cfquery datasource="#dns#" name="local.rs.q" maxrows="5">
    select replace(text, "/webimages/", "http://domain.com/webimages/") as text
    from   table
  </cfquery>

  <cfreturn rs.q> 
</cffunction>
选择替换(文本“/webimages/”,“http://domain.com/webimages/)作为文本 从桌子上


选择文本
从桌子上

选择替换(文本“/webimages/”,“http://domain.com/webimages/)作为文本
从桌子上


选择文本
从桌子上

是的,它可以。ReReplace()似乎是适合此工作的函数。嗨,丹,谢谢,但你能提供一个小例子吗?(但正如Al所说,更简单的功能可能是足够的,并且还考虑什么替代您的数据库提供的功能)。我正打算建议使用在您的SQL替换,但@ PeterBoughton击败我。是的,它可以。ReReplace()似乎是适合此工作的函数。嗨,丹,谢谢,但你能提供一个小例子吗?(但正如Al所说,更简单的功能可能是足够的,并且还考虑什么替代您的数据库提供的功能)。我正建议使用替换在您的SQL,但@ PeterBoughton殴打我。
<cffunction name="test" access="remote" returnformat="plain" output="false">
  <cfquery datasource="#dns#" name="local.rs.q" maxrows="5">
    select text
    from   table
  </cfquery>

  <cfreturn replace(serializeJSON(rs.q),
                "\/webimages\/",
                "http:\/\/domain.com\/webimages\/",
                "all")> 
</cffunction>