开发者

jQuery and Native JavaScript Array - error

开发者 https://www.devze.com 2023-01-05 12:24 出处:网络
var tmpANArray = []; for (var i in associatedPpl) { tmpANArray.push(associatedPpl[i]); } alert(\'abo开发者_开发知识库ut to call toJSON on AssociatedPpl\');
var tmpANArray = [];
for (var i in associatedPpl) {
    tmpANArray.push(associatedPpl[i]);
}
alert('abo开发者_开发知识库ut to call toJSON on AssociatedPpl');
alert(tmpANArray);
// the next line fails because $.toJSON is getting fed a function
var jsonEncodedAssociatedPpl = $.toJSON(tmpANArray);

What part of JavaScript/jQuery am I missing?

UPDATE The JS JSON lib was jquery.json-1.3.min.js


You have your for cycle wrong, it is actually a foreach so your i variable should not be used to index the array, because its the value itself, change it to:

var tmpANArray = [];
for (var i in associatedPpl) {
    tmpANArray.push(i);
}

Or why not use the associatedPpl array directly?


there's no toJSON natively in Jquery. Do you mean to use getJSON()? Are you involving a function that you haven't provided information about?

getJSON documentation: http://api.jquery.com/jQuery.getJSON/

0

精彩评论

暂无评论...
验证码 换一张
取 消