TypeError: invalid 'in' operand obj

尝试在程序去访问远程的Web API,它在运行时,出现异常: 

TypeError: invalid 'in' operand obj




由于从服务器返回的数据是json。
当我们需要得到这些数据时,还得需要Parse。
因此我们把代码稍微修改一下:
 
$(function () {
            $.ajax({
                type: "GET",
                url: "http://localhost:9001/api/size",                
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) { 
                    data = $.parseJSON(data);
                    $.each(data, function (index, item) {
                        //...
                    });                  

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        });
Source Code


原文地址:https://www.cnblogs.com/insus/p/5667571.html