【发布时间】:2013-06-18 20:35:46
【问题描述】:
我正在四处寻找与 Coldfusion 合作以将反序列化 JSON 文件构建到表中的一些最新材料。到目前为止,我正在使用 链接如:
[ADobe 反序列化 JSON][1] 我使用 JSONLINT.com 检查 JSON 文件是否有任何错误(没有错误) 我还查看了上面链接上的示例,发现它引发了如下所示的 CF 错误![在此处输入图像描述][2]
我只是试图解析来自另一个本地服务器的数据,我使用上面链接中的代码作为参考。 当我完全复制并粘贴代码时,它会导致我出现 CF 错误: 如果你能引导我找到更多可以帮助我解决这个问题的文档? 我通常利用 CFdump 的优势通过冷融合从 SQL 数据库中的数据创建页面,我想尝试以不同的方式进行操作
<!--- Get the JSON Feed --->
<cfhttp url="http://localhost:8500/LearnJS/dataconv.cfm">
<!--- JSON data is sometimes distributed as a JavaScript function.
The following REReplace functions strip the function wrapper. --->
<cfset theData=REReplace(cfhttp.FileContent,
"^\s*[[:word:]]*\s*\(\s*","")>
<cfset theData=REReplace(theData, "\s*\)\s*$", "")>
<!--- Test to make sure you have JSON data. --->
<cfif !IsJSON(theData)>
<h3>The URL you requested does not provide valid JSON</h3>
<cfdump var="#theData#">
<!--- If the data is in JSON format, deserialize it. --->
<cfelse>
<cfset cfData = DeserializeJSON(theData)>
<!--- Parse the resulting array or structure and display the data.
In this case, the data represents a ColdFusion query that has been
serialized by the SerializeJSON function into a JSON structure with
two arrays: an array column names, and an array of arrays,
where the outer array rows correspond to the query rows, and the
inner array entries correspond to the column fields in the row. --->
<!--- First, find the positions of the columns in the data array. --->
<cfset colList=ArrayLen(cfData.COLUMNS)>
<cfset cityIdx=ListFind(colList, "City")>
<cfset tempIdx=ListFind(colList, "Temp")>
<cfset fcstIdx=ListFind(colList, "Forecasts")>
<!--- Now iterate through the DATA array and display the data. --->
<cfoutput>
<cfloop index="i" from="1" to="#ArrayLen(cfData.DATA)#">
<h3>#cfData.DATA[i][cityIdx]#</h3>
Current Temperature: #cfData.DATA[i][tempIdx]#<br><br>
<b>Forecasts</b><br><br>
<cfloop index="j" from="1" to="#ArrayLen(cfData.DATA[i][fcstIdx])#">
<b>Day #j#</b><br>
Outlook: #cfData.DATA[i][fcstIdx][j].WEATHER#<br>
High: #cfData.DATA[i][fcstIdx][j].HIGH#<br>
Low: #cfData.DATA[i][fcstIdx][j].LOW#<br><br>
</cfloop>
</cfloop>
</cfoutput>
</cfif>
【问题讨论】:
-
错误信息是什么?
-
您使用的是什么版本的 ColdFusion 服务器?
-
你能用firebug之类的东西发布原始的json字符串吗?
标签: javascript json multidimensional-array coldfusion cfml