Javascript $.parseJSON(…)。每个都不是函数

Javascript $.parseJSON(…)。每个都不是函数,javascript,jquery,json,Javascript,Jquery,Json,在js文件中,我有下面的代码 使用这种语法是可以的 $(jQuery.parseJSON(category)).each(function() { $(selector).append($('<option>').text(this.name).attr('value', this.contactCategoryId)); }); 也许有更好的解决方案。获取格式良好的JSON字符串并返回结果JavaScript值 所以 $.parseJSON(类别)返回一个javasc

在js文件中,我有下面的代码

使用这种语法是可以的

$(jQuery.parseJSON(category)).each(function() {  
    $(selector).append($('<option>').text(this.name).attr('value', this.contactCategoryId));
});
也许有更好的解决方案。

获取格式良好的JSON字符串并返回结果JavaScript值

所以

$.parseJSON(类别)
返回一个javascript值

何处为

$($.parseJSON(category))
返回jQuery对象

As只能与jQuery对象一起使用。您将收到错误$.parseJSON(…)。每个都不是一个函数

在您的情况下,这是使用
jqueryeach
的正确方法

$(jQuery.parseJSON(category)).each(function() {  
    $(selector).append($('<option>').text(this.name).attr('value', this.contactCategoryId));
});
$(jQuery.parseJSON(category)).each(function(){
$(选择器).append($('').text(this.name).attr('value',this.contactCategoryId));
});
文档说parseJSON“返回结果JavaScript值”。它不返回jQuery对象,因此不能像那样对其进行链接。因此,jQuery.parseJSON(json)和$.parseJSON(category)是相同的东西,请参见此。。
$.each(jQuery.parseJSON(category), function () {
   ...
});
$(jQuery.parseJSON(category)).each(function() {  
    $(selector).append($('<option>').text(this.name).attr('value', this.contactCategoryId));
});