有关TypeError: invalid 'in' operand obj的错误


var data: { name: "John", location: "Boston" }
$.each(data, function(key, val) { items.push('<li id="' + key + '">' + val + '</li>'); });

  用$.each解析的时候,in对字符串不管用

  修改代码为:

data: { name: "John", location: "Boston" }

obj= $.parseJSON(data);

 $.each( obj, function(key, val) {
         items.push('<li id="' + key + '">' + val.name+ '</li>');
 });

 

posted @ 2017-01-11 22:36  zhongJaywang  阅读(162)  评论(0编辑  收藏  举报