1

我正在四处寻找与 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>
4

1 回答 1

1

ArrayLen()返回一个整数,即数组的长度。在以下几行...

<cfset colList=ArrayLen(cfData.COLUMNS)> 
<cfset cityIdx=ListFind(colList, "City")>

您将 colList 设置为 ArrayLen() (整数)的返回值,然后尝试将其作为列表引用。这可能会导致错误。

于 2013-06-18T23:49:56.843 回答