Javascript 得到一个;TypeError:无效';在';操作数a";在WordPress中

Javascript 得到一个;TypeError:无效';在';操作数a";在WordPress中,javascript,jquery,json,wordpress,each,Javascript,Jquery,Json,Wordpress,Each,所以我得到了一个TypeError:invalid'in'操作数WordPress中的一个错误(不确定是否与之相关),我也不确定代码到底出了什么问题 以下是相关代码: e_jsonObj = []; $.each(the_wpcc_posts, function(i, the_wpcc_post) { var e_post_id = the_wpcc_post[i].ID; var e_title = the_wpcc_post[i].post_title

所以我得到了一个TypeError:invalid'in'操作数WordPress中的一个错误(不确定是否与之相关),我也不确定代码到底出了什么问题

以下是相关代码:

e_jsonObj = [];            
$.each(the_wpcc_posts, function(i, the_wpcc_post) {
    var e_post_id = the_wpcc_post[i].ID;
    var e_title = the_wpcc_post[i].post_title;
    var e_start = the_wpcc_post[i].post_date_gmt;

    e_item = {}
    e_item ["id"] = e_post_id;
    e_item ["title"] = e_title;
    e_item ["start"] = e_start;

    console.log(e_item);

    e_jsonObj.push(e_item);         

});

非常感谢您提供的任何帮助。

通过在每个
循环之前解析数据来尝试这种方法。
似乎您正在尝试对字符串进行迭代,这导致了此错误

e_jsonObj = [];
data = $.parseJSON(the_wpcc_posts);  // parsing data          
$.each(data, function(i, the_wpcc_post) {
    var e_post_id = the_wpcc_post[i].ID;
    var e_title = the_wpcc_post[i].post_title;
    var e_start = the_wpcc_post[i].post_date_gmt;

    e_item = {}
    e_item ["id"] = e_post_id;
    e_item ["title"] = e_title;
    e_item ["start"] = e_start;

    console.log(e_item);

    e_jsonObj.push(e_item);         

});

通过在
每个循环之前解析数据来尝试这种方法。
似乎您正在尝试对字符串进行迭代,这导致了此错误

e_jsonObj = [];
data = $.parseJSON(the_wpcc_posts);  // parsing data          
$.each(data, function(i, the_wpcc_post) {
    var e_post_id = the_wpcc_post[i].ID;
    var e_title = the_wpcc_post[i].post_title;
    var e_start = the_wpcc_post[i].post_date_gmt;

    e_item = {}
    e_item ["id"] = e_post_id;
    e_item ["title"] = e_title;
    e_item ["start"] = e_start;

    console.log(e_item);

    e_jsonObj.push(e_item);         

});

谢谢你的回答!然而,这似乎引发了另一个问题。这就是我现在得到的错误:SyntaxError:JSON.parse:JSON数据第1行第1192列的JSON数据后出现意外的非空白字符谢谢您的回答!然而,这似乎引发了另一个问题。这就是我现在得到的错误:SyntaxError:JSON.parse:在JSON数据的第1行第1192列的JSON数据之后出现意外的非空白字符