我可以将一个数组分成两个单独的数组,原始数组中的每个元素都用“:”分隔吗? “:”之前的文本进入array1,“:”之后的文本进入array2
<cfset tempArr = DeserializeJSON(URL.data) />
<cfset selectList = "" />
<cfloop array=#tempArr# index="i">
<cfset selectList = listappend(selectList,i) />
</cfloop>
现在这段代码抓取整个元素而不是单独的。
编辑
示例字符串将是:
名字:鲍勃
first_name 进入 selectList1
Bob 进入 selectList2
宏伟的计划同样会有其他领域:
名字:鲍勃
姓氏:Shmo
年龄:27
等等...
编辑:答案
问题已通过使用代码解决
<!---Variables--->
<cfset temp1 = "" />
<cfset temp2 = "" />
<cfset selectList1 = "" /><!---Holds column names for tables--->
<cfset selectList2 = "" /><!---Holds query parameters for column names. Ie,
values for use in the WHERE clause--->
<cfloop array=#tempArr# index="i"><!---Loop through contents of the array--->
<cfset temp1 = GetToken(i,1,":")/><!---Store the column name--->
<cfset temp2 = GetToken(i,2,":")/><!---Query parameter--->
<cfset selectList1 = listAppend(selectList1, temp1)/><!---Adds to list of column names--->
<cfset selectList2 = listAppend(selectList2, temp2)/><!---Adds to the list of query parameters--->
</cfloop>
最佳答案
我认为没有看到您的数组示例,您的意思是将数组中的数据拆分为两个列表?
<cfset selectList1 = listAppend(selectList1, listFirst(i,':')) >
<cfset selectList2 = listAppend(selectList2, listLast(i,':')) >
关于arrays - Coldfusion 将一个阵列一分为二,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16948546/