- json对象转数组
-
后台返回的数据格式 {first: 1, second: 2, third: 3, fourth: 4, fifth: 5,sixth:6}(多处使用)
页面需要用到的格式[ {value: 1, name: 'first'}, {value: 2, name: 'second'}, {value: 3, name: 'third'}, {value: 4, name: 'fourth'}, {value: 5, name: 'fifth'}, {value: 6, name: 'sixth'} ]
success: function(data,textStatus, xhr) {
if(data instanceof Object){
console.log("this a object");
}
console.log(data);
for(var ele in data){
array.push(data[ele]);
}
console.log(array);
setOp(array);
setPie(data);// 这里需要使用
var token = xhr.getResponseHeader("token");
sessionStorage.setItem("token",token);
},
3.
4.已查看的链接
converting-a-js-object-to-an-array-using-jquery
convert-object-to-array-in-javascript