【问题标题】:Error parsing json created from a cfquery解析从 cfquery 创建的 json 时出错
【发布时间】:2013-09-26 01:54:20
【问题描述】:

我终其一生都无法弄清楚这是怎么回事。通常,我不会通过 json 从查询中返回数据,但在这种情况下我需要这样做。

这里是 CFC 函数:

<cffunction name="f1" access="remote" returnformat="JSON" >
    <!---query goes here --->
    <cfreturn thequery>
</cffunction>

这是 JSON:

{"COLUMNS":["C1"],"DATA":[["1"],["2"],["3"]]}

通常,我会创建一个结构,并用我想要返回的数据填充它,一切正常。

我将它传递回调用页面,并根据需要使用它,但无论出于何种原因,我似乎无法让 json 在调用页面上正确解析。我收到JSON.parse: unexpected character error

jQuery:

$.post("myCFC.cfc",{method:"f1"},
    function(response){
        var data = $.parseJSON(response);
        //doing stuff here, but can't parse the json, so it doesn't matter
    },
    "json");

所以,我想我会尝试只使用数据,因为在这种特殊情况下我不关心列名。那没有用,所以现在我在这里。

有人能解释一下我做错了什么吗?

【问题讨论】:

    标签: jquery coldfusion cfml


    【解决方案1】:

    如果您提供 json 数据类型,请勿使用 $.parseJSON。 jQuery 会自动为你做这些。

    $.post("myCFC.cfc",{method:"f1"},
        function(data){
            //var data = $.parseJSON(response);
            //doing stuff here, but can't parse the json, so it doesn't matter
        },"json"); // <-- here is where you supplied the json datatype
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      • 1970-01-01
      相关资源
      最近更新 更多