ColdFusion中的JSON解析问题
Issues parsing JSON in ColdFusion
我正在寻找一些使用Coldfusion将反序列化JSON文件构建到表中的最新材料。到目前为止,我正在使用链接,如:
[ADobe反序列化JSON][1]我使用JSONLINT.com来检查JSON文件的任何错误(没有)我还查看了上面链接上的示例,发现它抛出了如下所示的CF错误![2]
我只是想从另一个本地服务器解析数据,我使用的代码从上面的链接作为参考。当我复制和粘贴代码完全导致我CF错误:如果你能给我更多的文档来帮助我解决这个问题吗?我通常通过coldfusion利用CFdump的优势从SQLdatabase中的数据创建页面。我想尝试用不同的方法
<!--- 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>
ArrayLen()返回一个整数,数组的长度。
<cfset colList=ArrayLen(cfData.COLUMNS)>
<cfset cityIdx=ListFind(colList, "City")>
将colList设置为返回ArrayLen()(一个整数),然后尝试将其作为列表引用。
相关文章:
- Ext.js从json构建模型关系的问题
- 将数据加载到使用JSON返回的表单字段时出现问题
- 在javascript中使用json数据导致问题
- 神秘的ajax json请求问题jQuery
- JavaScript/jQuery JSON数组问题-值为未定义
- 从第三方服务器发出解析json的问题
- 获取json结果的身份验证问题
- 关于复杂JSON解析(angularjs和javascript)的问题
- JSON分析拼接问题
- 使用.map解析JSON对象时出现问题
- Javascript/Json日期转换问题
- Webgl 加载 json 模型问题
- 从 JSON 对象获取数据时出现问题
- JSON 格式问题
- 使用 jQuery.map 后使用 JSON.stringify 的问题
- 使用 GitHub API 在 dojo 中执行 PUT 更新会返回 400:解析 JSON 时出现问题
- node.js+MySQL;JSON结果-回调问题&没有响应客户端
- SAPUI5绑定问题:json文件中维护的列表项链接不起作用
- 使用jQuery进行谷歌地图api调用时出现问题(JSON未返回)
- ExtJS中提交的响应有问题(JSON中的响应,但HTML输入的地方)