有如下json
var d={ "msShops": [ { "shopId": 1000002418, "address": null, "agentId": 0, "comments": null, "companyId": "1000002417", "invalidDate": 4593859200000, "isPost": "1", "linkMan": "张二狗", "opMan": null, "phone": "0755-28419014", "registDate": 1330683908000, "shopName": "二狗红河店", "headimgurl": null, "smsNumber": 1, "sonCompanyId": "1000002417", "reserveendtime": 0, "reservestarttime": 0, "mmUserSms": null, "msCompany": { "companyId": 1000002417, "address": null, "companyCode": "二狗造型时尚店", "companyName": "二狗造型时尚店", "companyType": "1", "linkMan": "张二狗", "openAccount": "Y", "parentId": "0", "phone": "13570850825", "status": "1" }, "wxPhotos": null }, { "shopId": 2001106074, "address": "广东 深圳", "agentId": null, "comments": null, "companyId": "2001106073", "invalidDate": 1432816801000, "isPost": "0", "linkMan": "王店长", "opMan": null, "phone": "15818515787", "registDate": 1377664321000, "shopName": "路易士", "headimgurl": null, "smsNumber": 962, "sonCompanyId": "2001106073", "reserveendtime": 0, "reservestarttime": 0, "mmUserSms": null, "msCompany": { "companyId": 2001106073, "address": "广东 深圳", "companyCode": "路易士", "companyName": "路易士", "companyType": "1", "linkMan": "王店长", "openAccount": "Y", "parentId": "0", "phone": "15818515787", "status": "0" }, "wxPhotos": null } ], "meta": { "rescode": 1, "msg": null, "url": null, "res1": null, "res2": null } }
我使用JS来取值(jquery),就报错了,尽管在chrome控制台能拿到值,但报错阻止了代码继续运行。
for(var k in d.msShops){ console.log(d.msShops[k].shopId); }
报错如下:
你先试着
console.log(d.msShops[k]);
好像数据变化的,不推荐用for(var k in array)的写法
for(var k in d.msShops){ console.log(d.msShops[k].shopId); }
改成下面的试试输出的结果
var lengths = d.msShops.length;
for(var i=0;i<lengths;i++){
var tempShop = d.msShops[i];
console.log(tempShop);
console.log(tempShop.shopId);
}
@wakasann: 感谢回复,我刚取出来试了 又没问题 但放在环境中的JS就出问题··