我正在尝试使用ColdFusion(版本7.0.2.142559)将CSV文件加载到数组中。目前我遇到以下错误:
无法将coldfusion.runtime.Struct类型的标量值分配给二维ColdFusion数组。 ColdFusion 2维数组只能容纳1维ColdFusion数组和Java列表对象。
我的CSV文件按照以下格式设置:
a,b
c,d
e,f
这是我第一次使用ColdFusion,所以可能有一些简单的语法错误我无法看到。以下是代码:
<!--- get the current full path of the current --->
<cfset currentPath = getCurrentTemplatePath()>
<cfset currentDirectory = getDirectoryFromPath(currentPath)>
<!--- get and read the CSV-TXT file --->
<cffile action="read" file="#currentDirectory#/smalltest.csv" variable="csvfile">
<!--- create a new array --->
<cfset array=ArrayNew(2)>
<!--- loop through the CSV-TXT file on line breaks and insert into database --->
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">
<cfset array[#index#][1]=#listgetAt('#index#',1, ',')#>
<cfset array[#index#][2]=#listgetAt('#index#',2, ',')#>
</cfloop>
<cfdump var=#array#>
奖励:
顺便说一下,如果有某种方式可以从ColdFusion中调用PHP文件,那将节省我很多时间,因为我已经在PHP中完成了整个脚本(这只是一个小部分)。我了解到ColdFusion自定义标签(标签<cf_php>
非常适合我),但管理员表示不行,因此我必须使用ColdFusion或找到一些通过ColdFusion渲染PHP的方法。框架、JavaScript或<cfhttp>
标签都是我认为可能有效的方法......如果您有任何想法,请告诉我。
<cf_php>
看起来是个好主意,如果我的服务器支持自定义标签,但事实并非如此。我还有什么理由忘记<cf_php>
? - ubiquibacon