JQuery JSON数据处理
使用如下代码:
$("#click").click(function(){
$.ajax({
url: "{% url 'Analyse:getLastMonthDataByCountry'%}",
type: "POST",
success: function (data) {
str = "";
console.log(data);
$("#result").html("");
var confirm_add = new Array();
var confirm = new Array();
var dead = new Array();
var heal = new Array();
$.each(data,function(i,tmp){
confirm_add.push(tmp.confirm_add);
confirm.push(tmp.confirm);
dead.push(tmp.dead);
heal.push(tmp.heal);
});
console.log(confirm);
}
});
});
重要的是each怎么用,each有两个参数,第一个为迭代器位置,第二个为值。
如果是数组的话,第一个值相当于0...n,第二个即数组的值;
如果是字典,第一个为key,第二个为value。
可以这么像,数组是特殊的字典,以下标为key即可。

浙公网安备 33010602011771号